There is the defined and exists functions.
snip...
my @row = split(/;/, $array[$_]);
if ( defined @row ) {
$hash{$_} = \@row;
} else {
print "Empty line at: $_\n";
}
snip...
Alternately the defined could be exists.
Some comments:
1) Since you are not returning slices from your split, there is no need for the parentheses surrounding it.
2) Within the split itself, are you afraid that a semicolon will be interpreted? If so dont be, within the regular expression it is treated as a literal character. If on the other hand you are matching a literal backslash, you need to change the regex to /\\;/, as the back slash is a metacharacter.
3) Since you appear to be using the line number as a hash index, you could try something along the lines of the following which uses $. This var keeps track of what line you are on in the file in question (Note it begins counting at 1 not 0 like normal). This trick will reduce the memory you use while running this chunk of code
open(IN, "$file") || die "Cant open $file\nReason: $!\n";
while (<IN>) {
chomp();
my @row = split(/;/);
if ( defined @row ) {
$hash{$.} = \@row;
} else {
print "Empty line in $file at line: $.\n";
}
}
4) Since I my'd @row inside of the while loop, every iteration of the loop @row will be emptied by perl itself, which can avoid the redundant line @row = (); at the end of your loop.
Just some pointers :)
/* And the Creator, against his better judgement, wrote man.c */