in reply to Possible useless use of map
I think your code could have been written as:
If you don't have =1, it is easier to see this in a foreach loop. And it means the same thing as your map{}.foreach my $num (@$arr) { $hr->{$num} =1; }
#!/usr/bin/perl -w use strict; use strict; use warnings; use diagnostics; use Data::Dumper; my $arr = [1,2,3]; my $hr = undef; foreach my $num (@$arr) { $hr->{$num} =1; } print Dumper $hr; __END__ prints: $VAR1 = { '1' => 1, '3' => 1, '2' => 1 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Possible useless use of map
by Jenda (Abbot) on Mar 18, 2010 at 17:00 UTC | |
by Marshall (Canon) on Mar 20, 2010 at 01:52 UTC | |
by Jenda (Abbot) on Mar 20, 2010 at 10:22 UTC | |
|
Re^2: Possible useless use of map
by Anonymous Monk on Mar 18, 2010 at 12:00 UTC | |
by Anonymous Monk on Mar 18, 2010 at 14:04 UTC | |
by Marshall (Canon) on Mar 20, 2010 at 06:56 UTC | |
by Anonymous Monk on Mar 20, 2010 at 07:19 UTC | |
by Marshall (Canon) on Mar 30, 2010 at 09:49 UTC | |
|
Re^2: Possible useless use of map
by JavaFan (Canon) on Mar 18, 2010 at 15:07 UTC | |
by Marshall (Canon) on Mar 20, 2010 at 00:37 UTC | |
by JavaFan (Canon) on Mar 20, 2010 at 12:41 UTC |