wrote:
>
> suppose I create an array of arryanames
> @testarr=qw/@arr1 @arr2 @arr3/;
>
> The I assign values to those arrays
> @arr1=`ls /tmp`;
> @arr2=`ls /var`;
>
> Now I want to loop and print the first value in each array
> foreach $val (@testarr) {
> print $val[0];
> }
>
> The above does not work.
> Is there another way this can be done ?
Sure.
my @testarr;
for my $dir ( '/tmp', '/var' ) {
opendir my $dh, $dir or die "Cannot open $dir: $!";
push @testarr, [ grep !/^\./, readdir $dh ];
}
for my $val ( @testarr ) {
print map "$_\n", @$val;
}
John
--
use Perl;
program
fulfillment