PDA

View Full Version : How do i print the array using its reference


super_gunda
08-09-2007, 06:03 PM
HI,

I have the reference of array in $a

my $config = XMLin($vmkTest->{configFile}) or die "$!";
my $a = $config->{param}->{SCSIMemCMD}->{option};

How do I print the contents of array?

Thanks in adv
R!

super_gunda
08-09-2007, 06:23 PM
use $$ to dereference the array

so, $$a[0] will give me the first element of the array


Thanks,
R

super_gunda
08-09-2007, 06:35 PM
To print the complete array use @$a

Thanks,
R

FishMonger
08-09-2007, 06:58 PM
To print the complete array use @$a

Thanks,
R

Yes, but you have to watch out for the "gatcha".

$a = [qw(1 2 3 4 5)];
print @$a;

outputs:
12345

which may not be what you wanted/intended.

print join ' ', @$a;

or
print "$_\n" for @$a;

or use some other variation of those