Tomte has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl # use strict; use Data::Dumper; my $test = { k4 => 1, k2 => 1, k3 => 1, k1 => 1}; my $first = 'k4'; my @list = map { [$_->[0], ($_->[0] eq $first ? '' : $_->[0])] } sort { $a->[1] cmp $b->[1] } map { [$_, ($_ eq $first ? '' : $_)] } keys %$test; print "Erg: " . Dumper(@list);
# # above code repeated # my @list2 = sort { $a->[1] cmp $b->[1] } map { [$_, ($_ eq $first ? '' : $_)] } keys %$test; print "Erg2: " . Dumper(@list2);
My Question is: Why used the (way more seasoned) perl-hacker this second (the leftmost) map-statement? I'm quite sure I'm missing a crucial point here but can't get it.
Thanks for your time,
regards,
Tomte
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mapping, Sorting, Mapping on hash-keys
by mugwumpjism (Hermit) on Jul 23, 2002 at 11:35 UTC | |
|
Re: Mapping, Sorting, Mapping on hash-keys
by jmcnamara (Monsignor) on Jul 23, 2002 at 11:51 UTC | |
|
Re: Mapping, Sorting, Mapping on hash-keys
by dimmesdale (Friar) on Jul 23, 2002 at 11:32 UTC | |
|
Re: Mapping, Sorting, Mapping on hash-keys
by Anonymous Monk on Jul 23, 2002 at 13:18 UTC |