Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Returning Array of Arrays (OOP)

by Fastolfe (Vicar)
on Dec 30, 2000 at 01:54 UTC ( [id://48965]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Returning Array of Arrays (OOP)

If you already have all of the data in memory it doesn't do much good to keep passing it out piecemeal like that. If you were reading from a file, you could use your function to read a single line and return an array of each split piece of that line in a fashion similer to fetchrow. If you really do want to pass out pieces of a pre-existing array like that, though, you can do it like this:
my @array = ([1, 2, 3], [4, 5, 6], [7, 8, 9]); # non-destructive my $index = 0; sub nextitem { return if $index > $#array; return @{$array[$index++]}; } # more elegant, but destroys @array sub nextitem { return unless @array; return @{shift(@array)}; }
Is this what you meant?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://48965]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.