Re: Looping through an anonymous array of arrays
[email protected] ("Jeff Peng")
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
On Sat, Jun 7, 2008 at 9:31 AM, Rodrick Brown <[email protected]> wrote: > my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; > > I have no problem returning single elements but how would one walk this list > of elements with say a for loop? > Try this code: use strict; my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; lookinto($arrayRef); sub lookinto { my $obj = shift; if (ref $obj) { for (@$obj) { lookinto($_); } } else { print "$_\n"; } } -- Jeff Peng - [email protected] Professional Squid supports in China http://www.ChinaSquid.com/