Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Map Vs Foreach

by Marshall (Canon)
on Nov 26, 2009 at 10:39 UTC ( [id://809524]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @arr1;
    @arr1 = map { push @arr1, ($_+ 2) } @data;
    
  2. or download this
    my @dataPlus2 = map { my $bullshit = 'XYZ'; #see below
                          $_ + 2
                        }@data;
    
  3. or download this
    foreach my $root (map { sqrt($_) }@data)
    {
       #do something with this square root...
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://809524]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-23 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found