Kandankarunai has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks consider the following code for $i ( 0 .. $#kk ) { print "\t [ @{$kk$i} ],\n"; } kk is an array of array.In the above code how i can assign [ @{$kk$i} ] to an array.

Replies are listed 'Best First'.
Re: Array of array
by Nikhil Jain (Monk) on May 05, 2011 at 06:23 UTC
    use strict; use warnings; use Data::Dumper; my @kk = (["Hello","Perl"], ["Monks"]); foreach my $i(0..$#kk){ my @test = @{$kk[$i]}; print Dumper(\@test); }

    Updated: Don't confuse with Data::Dumper, Do it like,

    use strict; use warnings; my @kk = (["Hello","Perl"], ["Monks"]); foreach my $i(0..$#kk){ my @test = @{$kk[$i]}; }

      Thank you for ur help.The Data dumper returns $VAR1 value how assign it into normal array .Sorry for this type of question.I am new to perl

        In the example below, the elements of the  @kk array are already array references (i.e., scalar values). No need to dereference them to arrays and then copy them into anonymous array constructors to make them array references: just use them directly.

        >perl -wMstrict -le "use Data::Dumper; ;; my @kk = ( [ qw(aa bb cc dd) ], [ qw(kk jj ll mm) ], ); ;; my $i = 1; my $arrayref = $kk[ $i ]; ;; print Dumper $arrayref; print @$arrayref; " $VAR1 = [ 'kk', 'jj', 'll', 'mm' ]; kkjjllmm
Re: Array of array
by Anonymous Monk on May 05, 2011 at 06:22 UTC
    by assigning it?