in reply to Perl script to read from a text file

Since you know the records' individual fields to be delimited by \t, and to be of a fixed width, you can use either split or unpack to grab each field. I chose split just because it's a more common idiom.

my $infile = "filename.dat"; my @records; { open my $fh , "<", $infile or die "Can't open $infile!\n$!"; my @records = map { chomp; [ split /\t/ ] } <$fh>; } { local $" = "\t"; print "@{$_}\n" foreach @records; }

Each record is held in an anonymous array, referenced by the top level array, @records.

Update: Be sure that if you turn this in as homework you've studied the idioms so that you can explain them. There's a good chance your professor hasn't yet covered everything I (intentionally) used in this example.


Dave