in reply to [Perl 6] List of length 2 or...
though perhaps a Perl 5 programmer would be more comfortable with the implicit iteration of a global regex:my %hash = $fh.slurp.comb(/ ^^ (\T*) \t (\N*) /);
But I think the explicit use of .comb is more readable.my %hash = $fh.slurp ~~ m:g/ ^^ (\T*) \t (\N*) /;
If I didn't want to slurp the file, I'd use the convenient .lines method instead of the generic but cryptic prefix:<=> operator. I might write some kind of list comprehension:
or maybe just the same thing written as a normal for loop:my %hash = ($0,$1 if / ^^ (\T*) \t (\N*) / for $fh.lines);
Or if I wanted to emphasize the data flow, I might use an explicit gather/take construct:my %hash = do for $fh.lines { / ^^ (\T*) \t (\N*) / and $0,$1; }
I guess there's still more than one way to do it in Perl 6. :)my %hash = gather for $fh.lines { take / ^^ (\T*) \t (\N*) / || (); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [Perl 6] List of length 2 or...
by Anonymous Monk on Oct 23, 2008 at 10:57 UTC | |
by moritz (Cardinal) on Oct 23, 2008 at 11:02 UTC |