SheridanCat has asked for the wisdom of the Perl Monks concerning the following question:
Normally I would do this with map(), thusly:my @arr = (4, 1, 6, 4, 3, 7); my %saw; @saw{ @arr } = (); # The line I'm not understanding my @new_arr = keys %saw; print sort @new_arr;
my @arr = (4, 1, 6, 4, 3, 7); my %saw = map{ $_ => undef } @arr; my @new_arr = keys %saw; print sort @new_arr;
Which I think is much more clear, but I woud like to understand what the first version is doing. Can someone shed some light on this for me?
I'd do a search, but I'm not sure what to search for.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: De-Duping An Array
by ikegami (Patriarch) on Dec 21, 2006 at 21:09 UTC | |
by SheridanCat (Pilgrim) on Dec 21, 2006 at 22:02 UTC | |
|
Re: De-Duping An Array
by GrandFather (Saint) on Dec 21, 2006 at 21:12 UTC | |
|
Re: De-Duping An Array
by shmem (Chancellor) on Dec 21, 2006 at 22:57 UTC | |
by ikegami (Patriarch) on Dec 21, 2006 at 23:02 UTC | |
|
Re: De-Duping An Array
by BrowserUk (Patriarch) on Dec 21, 2006 at 21:34 UTC | |
|
Re: De-Duping An Array
by ides (Deacon) on Dec 22, 2006 at 14:42 UTC |