> following the example in the perldsc (data structures cookbook), i
wrote this
> piece of code to create an array of arrays from a data file :
>
>
> #!/usr/bin/perl -w
> use strict ;
>
> my @AofA ; # array of arrays of file contents
> open (fh1, "</path/to/filename/filename.txt") or die ("no can do") ;
> while (<fh1>) {
> push @AofA, (split /\t/) ;
Your split is pushing the list that it generates onto the end of the
array, rather than pushing a single element (an anonymous array
reference onto the array). So you need,
push @AofA, [ split /\t/ ];
Square brackets declare an anonymous array reference. In addition to
perldsc you may want to read through
perldoc perllol
perldoc perlreftut
perldoc perlref
http://danconia.org
> }
>
> close (fh1) ;
>
> print $AofA[0] ;
> print "\n" ;
> # this gives me "cho" when what i wanted was "cho 249 837"
> # later, i was hoping to use $AofA[0][0] to access "cho"
>
> an example of the file follows (fields are separated by tabs in "real
life")
> cho 249 837
> abc 123 456
> abc 984 235
> nurb 246 973
>
>
> it appears the problem is where i am doing the "push" while reading
the file.
>
> suggestions?
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>