Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Passing multiple arrays to foreach loop (list flattening)

by LanX (Bishop)
on May 12, 2013 at 12:19 UTC ( #1033192=note: print w/replies, xml ) Need Help??


in reply to Re^2: Passing multiple arrays to foreach loop
in thread Passing multiple arrays to foreach loop

From all the answers you got, the one from Athanasius was IMHO the best so far.

It's elementary for Perl that @arrays and %hashes are flattened in list context, not only in the case of a foreach (LIST), but whenever the docs talk about "LIST" as parameter.

from perldata#List value constructors

LISTs do automatic interpolation of sublists. That is, when a LIST is evaluated, each element of the list is evaluated in list context, and the resulting list value is interpolated into LIST just as if each individual element were a member of LIST. Thus arrays and hashes lose their identity in a LIST--the list

(@foo,@bar,&SomeSub,%glarch)

contains all the elements of @foo followed by all the elements of @bar, followed by all the elements returned by the subroutine named SomeSub called in list context, followed by the key/value pairs of %glarch.

for instance
DB<105> @a=1..3 => (1, 2, 3) DB<106> @b=a..c => ("a", "b", "c") DB<107> @c=(@a,@b) => (1, 2, 3, "a", "b", "c")

HTH! =)

Cheers Rolf

( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033192]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2018-07-23 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (468 votes). Check out past polls.

    Notices?