in reply to Help with recurring "uninitialized variable" problem.

Change

   if ($one_line =~ !/^#+/)

to

   if ($one_line !~ /^#+/)

or

   unless ($one_line =~ /^#+/)

or if you really want

  if (!($one_line =~ /^#+/))

(and by the way you can drop the '+' in the regex)

dave

Replies are listed 'Best First'.
Re: Re: Help with recurring "uninitialized variable" problem.
by C_T (Scribe) on Apr 09, 2004 at 17:25 UTC
    if (!($one_line =~ /^#+/))
    That did the trick!

    I THINK I understand why...

    !~ is a new one on me, BTW. Very cool.

    Many thanks!

    CT

    Charles Thomas
    Madison, WI

      B::Deparse can shed some light . . .

      $ perl -MO=Deparse,-p -e '$one_line =~ !/^#+/' ($one_line =~ (not /^#+/));

      So what you were really doing was first matching /^#+/ against $_, taking the logical not of what that returned and then attempting to use the string version of that as a regexp to match against $one_line.

      Update: And to further explain, that meant you were always splitting and hence would sometimes get lines without all the fields you expected and those would be undefined.

        >B::Deparse can shed some light . . .

        This is a Perl module? Sorry, this statement doesn't make much sense to me yet.

        >$ perl -MO=Deparse,-p -e '$one_line =~ !/^#+/' >($one_line =~ (not /^#+/));
        >So what you were really doing was first matching /^#+/ against $_,

        Why is that? Doesn't the =~ operator mean that I'm matching against whatever is to the left of the operator? Was it matching against $_ because of where I put the "not" operator(!)?

        >taking the logical not of what that returned and then attempting to use the string version of that as a regexp to match against $one_line.

        I guess I wish I understood this better. I'll keep at it.

        Charles Thomas
        Madison, WI