Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Take this f.ex.:

    my @found;
    my @letters = $!word.split('');
    my $ord = $letter.ord;
    for 0..(@letters.elems - 1) -> $i {
        if @letters[$i].ord == $ord {
            @found.push($i);
        }
    }

    In Perl 6 you write this like so:

    my $ord = $letter.ord;
    my @found = map { .key }, grep { .value.ord == $ord }, $!word.split('').pairs;

    Although I don’t know why you don’t simply say this:

    my $l = $letter.substr(0,1);

    The resulting simplification should be obvious. Maybe you should even avoid having to do it in the first place:

    method guess_letter ($letter where { 1 == (~$_).length })