Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^5: hash array

by bart (Canon)
on Oct 09, 2012 at 18:25 UTC ( #998051=note: print w/replies, xml ) Need Help??

in reply to Re^4: hash array
in thread hash array

map is a looping function to apply an expression or a block to every item in a list (each item in turn assigned to $_), and collect/return the list of results. It's like:
my @results; foreach(@_) { push @results, &$CODE(); } return @results;
where $CODE is the expression (delimited by a comma) or block (no delimiter) in the first argument.


@output = map $_*2, 1 .. 10;
which is identical in result to
@output = map { $_*2 } 1 .. 10;
and which return the even numbers from 2 to 20; the double of all numbers between 1 and 10.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998051]
[oiskuu]: ... getlogin refers to tty owner; if you close STDIN, then getlogin returns undef. I get undef in my shell (running under X)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-06-23 19:16 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.