Re: Can't create 2d array in Perl
- From: mumia.w.18.spam+nospam@xxxxxxxxxxxxx (Mumia W.)
- Date: Tue, 29 Aug 2006 19:43:13 -0500
On 08/29/2006 07:01 PM, Gregg Allen wrote:
Hi:
I would like to read a tab delimited text file created in Excel into a 2d array. I don't understand why the following doesn't work. The $i and $j, along with the print statement, are only for debugging purposes.
It prints:
Can't use string ("") as an ARRAY ref while "strict refs" in use at file_vars.pl line 30, <FH> line 2.
Gregg Allen
*********************************************************
#!/usr/bin/perl -w
use strict;
my @arr ;
my $i = $ARGV[0];
my $j = $ARGV[1];
print $i . " \t" . $j . "\n";
open(FH,"<0817L.txt") or die "cannot open !$\n";
while(<FH>)
{
push @arr , split /\t/ ;
}
print $arr[$i][$j];
I'm really confused about what $i and $j are supposed to be, but I might do it this way:
use strict;
use warnings;
use File::Slurp;
use Data::Dumper;
my @arr = map [ split /\t/ ], read_file('0817L.txt');
print Dumper(\@arr);
__END__
WARNING: UNTESTED CODE
.
- References:
- Can't create 2d array in Perl
- From: Gregg Allen
- Can't create 2d array in Perl
- Prev by Date: Re: Switch, Ranges and Memory
- Next by Date: Re: Can't create 2d array in Perl
- Previous by thread: Can't create 2d array in Perl
- Next by thread: Re: Can't create 2d array in Perl
- Index(es):
Relevant Pages
|