If your input always follows a particular format, I often find it is useful to write a simple line-parsing sub that returns the correct info (if it exists in the line) and handles any lines that don't conform to the format.If you use a regex to match the format rather than splitting, i generally don't find it is that much slower, especially if you precomile the regex (/o modifier), and it gives you the peace of mind that you don't get errors like this.
sub parse_format{ my $line = shift; my ($date, $number,); ## for returning while ($line =~ m/^ #linestart (\d+\/\d+\/\d+\s+\d+) # capture date and first num +ber \,\s+ #junk in the middle (\d+) # capture the last bit $ # end of string /ox ) { ($date,$number,) = ($1, $2,); } else { warn "\'$line\' did not conform to format. Skipping...\n"; } return ($date, $number,); }
Or something... I haven't tested this, *just as an example*!!
In reply to Re^3: stripping whitespace gives an 'unitialized value' error
by BioLion
in thread stripping whitespace gives an 'unitialized value' error
by stevemayes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |