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.


In reply to stripping whitespace gives an 'unitialized value' error by stevemayes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.