Ed Chester <> wrote: : Hi all. : : I have a hash %BITS something like this: : : $VAR1 = 'final_p'; : $VAR2 = 'p'; : $VAR3 = 'sp_pair'; : $VAR4 = [ : 's', : 'p' : ]; : : where the keys can be anything, and the values can be arrays : of any sensible size, including 1. I'm trying to write a loop : that returns each element of the values in an array, so : running it on the above it would yield something like @things : = ('p','s','p'). So, the trick is to always pretend like the : values are arrays. Then I remembered in the real world a hash : is only storing references anyway to anonymous arrays, so : figured it should be easy to dereference these and return : their guts, as it were. So I wrote (ignoring the returned : array for now, just printing): : : foreach my $bit (values %BITS) { : foreach my $thing (@{$bits}) { print "$thing\n"; } } :
my %bits = ( foo => 'final_p', bar => 'p', baz => 'sp_pair', qaz => [ 's', 'p' ], ); foreach my $bit ( values %bits ) { if ( ref $bit eq 'ARRAY' ) { print "$_\n" foreach @$bit; } else { print "$bit\n"; } } HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs