Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Advice on loops

by merlyn (Sage)
on May 03, 2007 at 15:27 UTC ( #613396=note: print w/replies, xml ) Need Help??


in reply to Advice on loops

Just use a recursive routine to drill down. Witness:
my @array=(['john','tom','peter'],['rose','teak'],['car','truck','jeep +'],['trees','plants'],['good','bad','ugly']); my @arrayindex=(3,1); my @wanted = @array[@arrayindex]; # get slice show(@wanted); sub show { if (ref @_[0]) { # still recursing for (@{+shift}) { show(@_, $_); } } else { # end case print "@_\n"; # do what you want with the results here } }
This prints:
trees rose trees teak plants rose plants teak

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2021-06-24 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (133 votes). Check out past polls.

    Notices?