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

Hi monks.i have a file.i want to make an array of arrays from this file but i dont want first element.i have written following code but there is problem that i cant understand.please help me.

#!/usr/bin/perl -w use strict; my @AoA; my $aref; open (IN,'<result'); while(<IN>){ push @AoA,[split]; } for $aref ( @AoA ) { shift @$aref ; }

i want finally @AoA .

Replies are listed 'Best First'.
Re: array of arrays
by moritz (Cardinal) on Jul 28, 2011 at 12:20 UTC

      But how can i put them again in @AoA? is it possible with my code,how i change the code?

Re: array of arrays
by JavaFan (Canon) on Jul 28, 2011 at 12:56 UTC
    I assume you don't want the first column of each line to be put in the datastructure. If it's something else you want, be more clear. If there's something in your datastructure that you don't want, just don't put it there (untested code):
    use strict; use warnings; open my $fh, "<", "result" or die "open: $!"; while (<$fh>) { my @chunks = split; push @AoA, [@chunks[1..$#chunks]]; } close $fh or die "close: $!";

      thank you so much.but a question for learning! where is shift?! how did you do this? i mean how did you omit the first element?

Re: array of arrays
by Anonymous Monk on Jul 28, 2011 at 12:46 UTC
    PerlMonks is not a code-writing service ...

      thank you, i know that.i tried this code but it doesnt work.

      #!/usr/bin/perl -w use strict; my @AoA; my $aref; my @array; open (IN,'<result'); while(<IN>){ push @AoA,[split]; } for $aref ( @AoA ) { shift @$aref ; @array=push(@array,@$aref); } for my $array(@array){ print @$array; }
Re: array of arrays
by persianswallow (Novice) on Jul 28, 2011 at 17:16 UTC

    may be you can use split as follow

    @array={'AAAA335.879','abcd','eghytr','rhty'} split(/^\W+\d+\.?\d*/,@array)