Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Returning lists vs arrays

by hardburn (Abbot)
on Jan 20, 2003 at 16:42 UTC ( #228389=note: print w/replies, xml ) Need Help??


in reply to Returning lists vs arrays

--Reposting my answer from the duplicated node--

I think you're confused by the distinction between arrays and lists. Lists are a bunch of values, while arrays are variables that hold values. See perlfaq4.

Outside your subroutine, the distinction doesn't matter. It will all look like arrays:

sub return_array { my @a = (0, 1, 2, 3); return @a; } sub return_list { return (0, 1, 2, 3); } my @array1 = return_array(); my @array2 = return_list();

Replies are listed 'Best First'.
Re: Re: Returning lists vs arrays
by ihb (Deacon) on Jan 20, 2003 at 16:54 UTC
    Outside your subroutine, the distinction doesn't matter.

    It does, depending on context. See Context aware functions - best practices? for an example of this.

    It will all look like arrays

    (Assuming list context.) Make that "lists" instead. A bunch of values are returned, and as you say yourself, that's a list.

    If you really want to return a list but the whole list is stored in an array you can do   return @stuff[0..$#stuff];

    ihb

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://228389]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2022-09-28 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?