I initially discussed this issue in the chatbox but the issue was not easily resolvable there.
The following code is part of a larger loop that iterates through files in a directory and this particular chunk iterates through the lines breaking them in two and assigning the two parts to two variables. The second variable then has the leading white space removed with the regex substitution s/^\s+//. The problem is that the code gives an 'unitialized value' error.
To clarify the issue I took the offending section and placed it in it's own file and ran just that against a single test file. Same result. So I've verified that the error is in this block of code and the error warning specifically complains about the line: $backlog =~ s/^\s+//;
The code that causes the error is as follows
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; open(REPORT, $ARGV[0]) || die("Error - Can't open $ARGV[0]: $!\n"); our $initial_datetime; our $backlog; while (<REPORT>) { last if /,-/; chomp; ($initial_datetime, $backlog) = split(","); $backlog =~ s/^\s+//; # just for testing purposes print $initial_datetime; print "\n"; print $backlog; print "\n"; }
The file that the code is being run against is this:
11/05/09 12, 3424 11/05/09 13, 3 11/05/09 14, 1 11/05/09 15, 30 11/05/09 16, 73 11/05/09 17, 1 ,-------------------- sum , 3532
The error message is:
Use of uninitialized value in substitution (s///) at qad.pl line 18, < +REPORT> line 1 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help...(removed)... Use of uninitialized value in print at qad.pl line 20, <REPORT> line 1 + (#1) Use of uninitialized value in print at qad.pl line 22, <REPORT> line 1 + (#1)
I've initialised the variables (I thought); I've assigned values to them on the split line. This has me completely confused.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |