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([EMAIL PROTECTED]);

__END__

WARNING: UNTESTED CODE


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to