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 = $arrayRef;

for (my $i = 0; $i < @flat; $i++) {
  splice @flat, $i, 1, @{$flat[$i]} while ref $flat[$i] eq 'ARRAY';
}

print "$_\n" foreach @flat;


Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to