By its design, map is intended for use with arrays, not scalars.

lists, not arrays!

Arrays are those things that have @. And even then, an array used in list context evaluates to a list of its elements.

@foo # array @Foo::bar # array @$foo # array @{ $bar } # array @{ $blah{blah}[1] } # array @list # array with a confusing name $array # scalar (possibly a reference) [ ... ] # scalar (reference to anonymous array) \@array # scalar (reference to named array) *foo{ARRAY} # scalar (reference to the package global @foo) print @array # list (print "gets" a list, not an array, # because @array is in list context) return @array # list! (again, array in list context) \(1, 2, 3) # list of references, not a reference to a list @foo = # array map { $_ + 1 } # list map { s/\n//g } # list @bar # list! (array in list context)
Subs get and return lists. List operators (like map) take lists. Arrays can be referenced, lists cannot. "Array context" exists, but only syntax-wise (\@ prototype or special syntax). Most of the time "list context" is what you really mean. Oh, and arrays can have names, lists cannot.

Please, learn the difference. It's confusing enough already even if you use the *correct* words.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


In reply to Re: Confessions of a back-alley map abuser by Juerd
in thread Confessions of a back-alley map abuser by dimar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.