Greetings most wise and helpful monks!

For whatever reason, this problem keeps cropping up, so I'm hoping someone can shed some light on the problem so I can eliminate it once and for all.

This code works:

while (<>) { if (!/^#+/) { ($source, $destination, $bytes) = split; $net_activity{$source}{$destination} += $bytes; }# ignore comments }# read in each line of the net log
This code does not:
my($one_line) = ''; while ($one_line = <>) { if ($one_line =~ !/^#+/) { ($source, $destination, $bytes) = split(/ /, $one_line); $net_activity{$source}{$destination} += $bytes; }# ignore comments }# read in each line of the net log
I get lots of these:
Use of uninitialized value in pattern match (m//) at ./net_traffic2 li +ne 14, <> line 5.
The program still WORKS (i.e. does what it's supposed to do), but it throws up all those warnings first.

I know I'm doing something Very Dumb(TM) here, but if someone could point it out I'd be extremely grateful. I want to understand this whole "unitialized variable" thing because it keeps coming up even when I think I've initialized the variable. Apparently Perl and I have different ideas of what that means, so I want to get in line.

Many thanks!

C_T

Charles Thomas
Madison, WI

In reply to Help with recurring "uninitialized variable" problem. by C_T

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.