Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: array assignment

by kvale (Monsignor)
on Nov 12, 2004 at 19:59 UTC ( #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
Node Status?
node history
Node Type: note [id://407503]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-05-30 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (172 votes). Check out past polls.

    Notices?