News for hackers. Stuff that matters.
Re:Data munging in Perl 6 vs. Perl 5 by Mithaldu on Tuesday December 09, 2014 @04:28PM (#8725899)
Two examples:

    $freq{substr $grade{$_}, 0, 1}++ for keys %grade;
better:

    $freq{$_}++ for map { substr $_, 0, 1 } values %grade;
best:

    my @letters = map { substr $_, 0, 1 } values %grade;
    $freq{$_}++ for @letters;
----------------------------

and

    open my $fh, '<:utf8', "grades.txt"
        or die "Failed to open file: $!";
    
    my %grade;
    while (<$fh>) {
        m/^(\w+) \s+ ([A-F][+-]?)$/x
        or die "Can't parse line '$_'";
        $grade{$1} = $2;
    };
better:

    use 5.010;
    use IO::All -binary, -utf8;
    
    my $line_format = qr/
        ^               	    # line start
        (?<student>\w+)         # name
        \s+                     # gap
        (?<grade>[A-F][+-]?)    # grade
        $                       # line end
    /x;
    
    my $fh = io->file("grades.txt");
    my %grade;
    while (my $line = $io->getline) {
        die "Can't parse line '$line'" if $line !~ $line_format;
        $grade{$+{student}} = $+{grade};
    }
Re:Data munging in Perl 6 vs. Perl 5 by hvs on Tuesday December 09, 2014 @10:58PM (#8727609)
Very nicely done. I use Perl in my everyday job, and its nice to see that some people still know how to write good Perl.
Re:Data munging in Perl 6 vs. Perl 5 by pjfl on Wednesday December 10, 2014 @10:27AM (#8729611)
You should have use strict; use warnings; then you would have noticed the my $fh and the $io->getline error
Re:Data munging in Perl 6 vs. Perl 5 by Mithaldu on Wednesday December 10, 2014 @10:32AM (#8729647)
Dammit, you're right. I was working in a buffer without perl instrumentation enabled because i was composing a comment, not a script. Now i can't edit the comment anymore. :/
Re:Data munging in Perl 6 vs. Perl 5 by Ultimatt on Wednesday December 10, 2014 @05:31AM (#8728559)
5.10 in production? Surely you're joking! 5.8 or bust.