Loading ...
Sorry, an error occurred while loading the content.
 

Re: Warnings in nested conditional test but not in parent?

Expand Messages
  • hooyar66
    ... second ... test ... first ... or ... I ... browse_frm/ ...
    Message 1 of 7 , Oct 10, 2006
      --- In perl-beginner@yahoogroups.com, "hooyar66" <pcbcad@...> wrote:
      >
      > --- In perl-beginner@yahoogroups.com, "hooyar66" <pcbcad@> wrote:
      > >
      > > --- In perl-beginner@yahoogroups.com, "Charles K.
      > > Clarkson" <cclarkson@> wrote:
      > > >
      > > > hooyar66 wrote:
      > > >
      > > >>In my program I have the following two test conditions, the
      second
      > > >>"if" is nested into the first.
      > > >>
      > > >>if($records->[$idx_r][$idx_f]){print $q->param($choice), ":
      > > >><b>$records->[$idx_r][$idx_f]</b><br>";
      > > >>#if($q->param($choice) =~ /(First|Mechanical|Logic check
      > > >>date)/){print $q->p()};}
      > > >>
      > > >>When I comment out the second "if" conditional the program runs
      > > >>without warnings, however if I enable the second "if" I get
      > hundreds
      > > >>of the following in my Apache error log:
      > > >>
      > > >>[Wed Oct 04 17:32:04 2006] [error] [client 192.168.14.35] [Wed
      > Oct 4
      > > >>17:32:01 2006] development.cgi: Use of uninitialized value in
      > join
      > > >>or string at (eval 26) line 15.
      > > >>
      > > >>I can't understand why I only get the warnings in the second
      test
      > > >>when the same variable $q->param($choice) is referenced in both
      > > >>tests? Shouldn't I also get the warnings when only using the
      first
      > > >>"if" test?
      > > >
      > > > If $choice is not defined, param() returns an empty string
      or
      > > > an empty list depending on context. It might also return these
      > > > results if $choice is defined, but the result of param() is not.
      > > > 'print' always assumes list context. Printing an empty list does
      > > > not raise a warning.
      > > >
      > > >
      > > > use strict;
      > > > use warnings;
      > > >
      > > > use CGI;
      > > >
      > > > my $q = CGI->new();
      > > >
      > > > # list context.
      > > > print '"', $q->param(undef), '"';
      > > >
      > > > # list context.
      > > > print '"', $q->param('foo'), '"';
      > > >
      > > > __END__
      > > >
      > > >
      > > > use strict;
      > > > use warnings;
      > > >
      > > > use CGI;
      > > >
      > > > my $q = CGI->new();
      > > >
      > > > # scalar context.
      > > > print '"', scalar $q->param(undef), '"';
      > > >
      > > > # scalar context.
      > > > print '"', scalar $q->param('foo'), '"';
      > > >
      > > > __END__
      > > >
      > > >
      > > >
      > > > HTH,
      > > >
      > > > Charles K. Clarkson
      > > > --
      > > > Mobile Homes Specialist
      > > > Free Market Advocate
      > > > Web Programmer
      > > >
      > > > 254 968-8328
      > > >
      > > > Don't tread on my bandwidth. Trim your posts.
      > > >
      > >
      > > I have now looked at this problem further and after various tests
      I
      > > believe my warnings are related to a bug in CGI.pm ver 2.91 - as
      > > discussed here:
      > >
      > > http://groups.google.co.uk/group/comp.lang.perl.modules/
      browse_frm/
      > > thread/53602ce8255efad1/
      > >
      >
      2d4648178b76ee9e?lnk=st&q=%22Use+of+uninitialized+value+in+join+or+string+at+(eval%22+cgi.pm&rnum=1&hl=en#2d4648178b76ee9e
      > >
      > > I am now trying to figure out how to use my existing "functions
      as
      > > class-methods".
      > >
      > > Can someone explain in beginners parlance how to implement the
      fix
      > as
      > > described in the linked thread? I am guessing I need to change
      the
      > > way I use the CGI object from
      > >
      > > my $q = new CGI;
      > >
      > > to a "class-method" format.
      > >
      > > Thanks for any help.
      > > NJH
      > >
      >
      > This link to the thread referred to may help:
      >
      > http://tinyurl.com/npta8
      >

      When using the following two lines of code:

      if($records->[$idx_r][$idx_f]){print $q->param($choice), ":
      <b>$records->[$idx_r][$idx_f]</b>", "<br>";
      if($q->param($choice) =~ /(First|Mechanical|Logic check
      date)/){print $q->p()};
      }

      I was getting the error:

      [Tue Oct 10 17:44:38 2006] [error] [client 192.168.14.35] [Tue Oct 10
      17:44:38 2006] development.cgi: Use of uninitialized value in join or
      string at (eval 26) line 15.

      I have now modified the code to:

      if($records->[$idx_r][$idx_f]){print $q->param($choice), ":
      <b>$records->[$idx_r][$idx_f]</b>", "<br>";
      if($q->param($choice) =~ /(First|Mechanical|Logic check
      date)/){print "<br>"};

      and I no longer get the error!? Simply changing {print $q->p()}; with
      the html equivalent {print "<br>"};

      I guess this must be a bug with CGI.pm, unless anyone knows better?

      Thanks
      NJH
    Your message has been successfully submitted and would be delivered to recipients shortly.