Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: array assignment

by kvale (Monsignor)
on Nov 12, 2004 at 19:59 UTC ( [id://407503]=note: print w/replies, xml ) Need Help??


in reply to array assignment

map makes this easy:
@a = (1,2,3); @b = (4,5,6); @result = map {$a[$_]+$b[$_]} 0..$#a;

-Mark

Replies are listed 'Best First'.
Re^2: array assignment
by Roy Johnson (Monsignor) on Nov 13, 2004 at 02:55 UTC
    Applying that to the date problem:
    my ($dd, $mm, $yyyy) = map {(0,1,1900)[$_] + ((localtime)[3..5])[$_]} +0..2;
    Not real pretty, but I guess that's why Tye invented Mapcar, which, if I read the docs right, one could use to solve the problem thus:
    my ($dd, $mm, $yyyy) = mapcar { $_[0] + $_[1] } [0,1,1900], [(localtim +e)[3..5]];
    (no extra map needed, Dragonchild).

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

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

    No recent polls found