Front page | perl.perl6.meta |
Postings from May 2001
perl5 to perl6
Thread Next
From:
Nathan Torkington
Date:
May 10, 2001 17:31
Subject:
perl5 to perl6
Message ID:
15099.12983.918000.739096@gargle.gargle.HOWL
Here's a program I use to count messages in my mailfile:
#!/usr/bin/perl -w
while (<>) {
if (($who) = /^From\s+\S+\s+\S+\s+(\S+\s+\S+)/) {
@r = reverse split ' ', $who;
$r[0] = sprintf("%02d", $r[0]);
$count{"@r"}++;
}
}
foreach (sort keys %count) {
printf("%s: %3d\n", $_, $count{$_});
}
Here's the corresponding perl6 program:
#!/usr/bin/perl -w
while (<$ARGS>) {
if (($who) = /^From\s+\S+\s+\S+\s+(\S+\s+\S+)/) {
@r = reverse split ' ', $who;
@r[0] = sprintf("%02d", @r[0]);
%count{"@r"}++;
}
}
foreach (sort %count) {
printf("%s: %3d\n", $_, %count{$_});
}
Notice the variable changes: %count{...} because I'm talking about the
hash %count. @r[0] because I'm talking about the array @r.
Nat
Thread Next
-
perl5 to perl6
by Nathan Torkington