in reply to Errors on loops over data
The best way to get line numbers is to get out of the habit of slurping. It is also better for memory consumption and not terribly difficult to do. Instead read line by line from the file and Perl will print out the data line number for you when you have an error.
use strict; use warnings; my @categories=qw/a b c/; my @master; #replace this line with a while statement+chomp+split #foreach my $d(@data){ while (my $line = <DATA>) { chomp $line; my $d = [ split(m{,}, $line) ]; my %h; foreach my $c(0 .. $#categories){ my $val=$d->[$c]; my $cat=$categories[$c]; $h{$val}=$cat; } push @master, \%h; } __DATA__ 1,2,3 4,5,6 7,8 10,11,12
prints out
Use of uninitialized value in hash element at YourScript.pm line 17, < +DATA> line 3.
Best, beth
|
|---|