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

RE: [PBML] Warnings for variable only in nested conditional test but not in parent?

Expand Messages
  • Charles K. Clarkson
    ... 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,
    Message 1 of 7 , Oct 4, 2006
    • 0 Attachment
      hooyar66 wrote:

      : 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.
    • Charles K. Clarkson
      ... Oopsie! It returns an undefined value of an empty list. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254
      Message 2 of 7 , Oct 4, 2006
      • 0 Attachment
        Charles K. Clarkson wrote:
        :
        : If $choice is not defined, param() returns an empty string or
        : an empty list depending on context.

        Oopsie! It returns an undefined value of an empty list.


        HTH,

        Charles K. Clarkson
        --
        Mobile Homes Specialist
        Free Market Advocate
        Web Programmer

        254 968-8328

        Don't tread on my bandwidth. Trim your posts.
      • hooyar66
        ... Many thanks Charles - your examples make the problem much clearer. NJH
        Message 3 of 7 , Oct 5, 2006
        • 0 Attachment
          --- In perl-beginner@yahoogroups.com, "Charles K.
          Clarkson" <cclarkson@...> wrote:
          >
          > Charles K. Clarkson wrote:
          > :
          > : If $choice is not defined, param() returns an empty string or
          > : an empty list depending on context.
          >
          > Oopsie! It returns an undefined value of an empty list.
          >
          >
          > HTH,
          >
          > Charles K. Clarkson
          > --
          > Mobile Homes Specialist
          > Free Market Advocate
          > Web Programmer
          >
          > 254 968-8328
          >
          > Don't tread on my bandwidth. Trim your posts.
          >


          Many thanks Charles - your examples make the problem much clearer.

          NJH
        • hooyar66
          ... 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:
          Message 4 of 7 , Oct 10, 2006
          • 0 Attachment
            --- 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
          • hooyar66
            ... hundreds ... Oct 4 ... join ... 2d4648178b76ee9e?lnk=st&q=%22Use+of+uninitialized+value+in+join+or+string+at+(eval%22+cgi.pm&rnum=1&hl=en#2d4648178b76ee9e
            Message 5 of 7 , Oct 10, 2006
            • 0 Attachment
              --- 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
            • hooyar66
              ... second ... test ... first ... or ... I ... browse_frm/ ...
              Message 6 of 7 , Oct 10, 2006
              • 0 Attachment
                --- 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.