What should be the code? That depends on what you want to do with the values in your original array. If all you want is to move them as-is (unmodified) into separate scalar variables, you don't need map at all:
sub show_scalars
{
my ( $str1, $str2, $str3 ) = @_;
print "Last was $str3, preceded by $str2, and $str1 was first\n";
}
my @array = qw/one two three/;
show_scalars( @array );
But as
pg showed in the first reply, map is good for when you want to derive a set of modified values from an array or list, by applying a chunk of code to each element.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.