in reply to Confessions of a back-alley map abuser

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' }

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.