in reply to Map Function Weirdness
Maybe this will help your understanding:
#!/usr/bin/perl use strict; use warnings; my %hash=(1=>10,2=>20,3=>30,4=>40,5=>50); my $max=0; my @out=map{ $_=$hash{$_}; if($_>$max){$max=$_} else { ()} # $_; }keys %hash; print "Max value was $max\n"; use Data::Dumper; print Dumper \@out; # prints Max value was 50 $VAR1 = [ 40, 50 ];
Note that the result of a block is the result of the last statement of a block. In case of an if-clause that might be the false value, in string context the empty string ''
PS: What for you is strangeness is for most of us a script working as it should. If you don't tell us what you would expect as output we can't tell you where your expectation is wrong
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Map Function Weirdness
by rthawkcom (Novice) on Nov 08, 2011 at 20:13 UTC |