jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
Most of the time map surprises me, it always generates output I don't expect. This time however it goes beyond this. Here is my test code:
This is truly map magic for me! Anyone out there who has already walked this path ?
CHeers LuCa
Update: thnx monks, I appreciate the help!!
Most of the time map surprises me, it always generates output I don't expect. This time however it goes beyond this. Here is my test code:
Which returns#! /usr/bin/perl -l use strict; use warnings ; my @arr = qw(1 2 3 4 5) ; my %h = map { "$_" => "$_" } @arr ; print "$_ --> $h{$_}" foreach ( keys %h ) ;
However when I change the map-line into: my %h = map { $_."" => "$_" } @arr ; it works and producessyntax error at ./t.pl line 7, near "} @arr " Execution of ./t.pl aborted due to compilation errors.
4 --> 4 1 --> 1 3 --> 3 2 --> 2 5 --> 5
This is truly map magic for me! Anyone out there who has already walked this path ?
CHeers LuCa
Update: thnx monks, I appreciate the help!!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: strange map behavior
by ikegami (Patriarch) on Feb 25, 2008 at 17:27 UTC | |
by jeanluca (Deacon) on Feb 25, 2008 at 19:24 UTC | |
by ikegami (Patriarch) on Feb 25, 2008 at 19:33 UTC | |
Re: strange map behavior
by kyle (Abbot) on Feb 25, 2008 at 17:32 UTC | |
Re: strange map behavior
by CountZero (Bishop) on Feb 25, 2008 at 19:36 UTC | |
by revdiablo (Prior) on Feb 26, 2008 at 04:24 UTC | |
Re: strange map behavior
by Anonymous Monk on Feb 25, 2008 at 19:12 UTC | |
by CountZero (Bishop) on Feb 25, 2008 at 19:44 UTC | |
by Anonymous Monk on Feb 25, 2008 at 22:51 UTC | |
Re: strange map behavior
by alexm (Chaplain) on Feb 26, 2008 at 20:28 UTC |
Back to
Seekers of Perl Wisdom