in reply to problem : return an array list

Just to show the upside of this perl feature, you can do:

foreach ( @array1, @array2, @array3) { ... }

And perl will step through all the arrays in turn. Also works in function calls and any other place where perl expects an array. Nifty, eh?

Update: Will work everywhere Perl expects a LIST. Juerd explains below.

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Re: problem : return an array list
by Juerd (Abbot) on Mar 31, 2002 at 15:00 UTC

    And perl will step through all the arrays in turn. Also works in function calls and any other place where perl expects an array. Nifty, eh?

    Well, nifty - yes. Correct - no.

    With for, perl expects a LIST, not an ARRAY. This is why for (1, 2, 3) also works.

    splice, push, pop, shift and unshift expect an ARRAY as their first argument. The big difference is that where a LIST is expected, an array is flattened as in your example. When an ARRAY is expected, you can only use a single array, not two arrays, not a hash.

    In the case of for (@array1, @array2, @array3), the list passed to for consists of all elements in the three arrays, not the three arrays themselves.

    (Please note that uppercased "LIST" and "ARRAY" are conventions used throughout the Perl documentation)

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk