Looping through an anonymous array of arrays

2008-06-06 Thread Rodrick Brown
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?

Re: Looping through an anonymous array of arrays

2008-06-06 Thread Jeff Peng
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,

Re: Looping through an anonymous array of arrays

2008-06-06 Thread Chas. Owens
On Fri, Jun 6, 2008 at 9:31 PM, 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? > You can treat an array reference like an array by

Re: Looping through an anonymous array of arrays

2008-06-06 Thread Gunnar Hjalmarsson
Rodrick Brown 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? One way: my $level = 0; breakdown( $arrayRef ); sub breakdown { my $ref = shift;

Re: Looping through an anonymous array of arrays

2008-06-07 Thread Aruna Goke
Gunnar Hjalmarsson wrote: Rodrick Brown 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? One way: my $level = 0; breakdown( $arrayRef ); sub breakdown {

Re: Looping through an anonymous array of arrays

2008-06-08 Thread Dr.Ruud
"Rodrick Brown" schreef: > 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? Start writing it differently, maybe like: my $data = [ 1, 2, 3, [ 'a',

Re: Looping through an anonymous array of arrays

2008-06-08 Thread Randal L. Schwartz
> "Aruna" == Aruna Goke <[EMAIL PROTECTED]> writes: Aruna> for my $item (@$arrayRef){ Aruna> print $item unless ref($item) eq 'ARRAY'; Aruna> if(ref($item) eq 'ARRAY'){ Aruna>for my $item1(@$item){ Aruna>print $item1 unless ref($item1) eq 'ARRAY'; Aruna> { Arun

Re: Looping through an anonymous array of arrays

2008-06-08 Thread Randal L. Schwartz
> "(Randal" == (Randal L Schwartz) <[EMAIL PROTECTED]> writes: (Randal> my @items = @$arrayRef; (Randal> while (@items) { (Randal> if (ref $items[0]) { (Randal> if (ref $items[0] eq "ARRAY") { (Randal> unshift @items, @{shift @items}; # replace arrayref with co

Re: Looping through an anonymous array of arrays

2008-06-10 Thread Rob Dixon
Rodrick Brown 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? use strict; use warnings; my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; my @flat = $arra