Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Perl CGI.PM: Use of uninitialized value $vals

by Anonymous Monk
on Apr 30, 2018 at 05:55 UTC ( [id://1213784]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Saw this in my web log file today:
Use of uninitialized value $vals in index at /homedir/perl5/lib/perl5/ +CGI.pm line 1243.
$vals is not initialised, yes, but what precondition caused the warning to be triggered?

Replies are listed 'Best First'.
Re: Perl CGI.PM: Use of uninitialized value $vals
by kcott (Archbishop) on Apr 30, 2018 at 08:52 UTC

    It's generated by code something like these:

    $ perl -wE 'my $vals; my $y = index($vals, "x")' Use of uninitialized value $vals in index at -e line 1. $ perl -wE 'my $vals; my $y = index("x", $vals)' Use of uninitialized value $vals in index at -e line 1.

    Look in /homedir/perl5/lib/perl5/CGI.pm, go to line 1243, and start investigating from there.

    — Ken

      I do not have code calling the method index, but rindex yes.

        What version of CGI do you have ?. In 3.65 the code was

        sub STORE { my $self = shift; my $tag = shift; my $vals = shift; my @vals = index($vals,"\0")!=-1 ? split("\0",$vals) : $vals; $self->param(-name=>$tag,-value=>\@vals); }

        In 4.37 it is

        sub STORE { my $self = shift; my $tag = shift; my $vals = shift; my @vals = defined($vals) && index($vals,"\0")!=-1 ? split("\0",$v +als) : $vals; $self->param(-name=>$tag,-value=>\@vals); }
        poj
Re: Perl CGI.PM: Use of uninitialized value $vals
by hippo (Bishop) on Apr 30, 2018 at 08:28 UTC

    Something like this will do it (note the "-w" which I suppose you are using too):

    #!/usr/bin/perl -w use CGI; CGI->STORE ('foo', undef);

    So you can trigger this by passing an undefined parameter value to STORE() but only with "-w". Use warnings instead if you don't want to see it.

      I do not have any CGI code calling CGI->STORE. Perhaps something else that calls CGI->STORE indirectly? What could it be?
Re: Perl CGI.PM: Use of uninitialized value $vals
by jsteng (Beadle) on Apr 30, 2018 at 06:51 UTC
    use warnings;
    can cause that warning message. but not fatal.
    usually happens with codes like
    use warnings; my %hash; if ($hash{'word'} =~ /world/) { }
    $hash{word} is not defined and will cause that warning.
    Make sure $hash{word} holds a valid value before using it or it will give you a warning.
Re: Perl CGI.PM: Use of uninitialized value $vals
by Anonymous Monk on Apr 30, 2018 at 22:16 UTC
Re: Perl CGI.PM: Use of uninitialized value $vals
by Anonymous Monk on Apr 30, 2018 at 06:24 UTC

    Saw this in my web log file today: $vals is not initialised, yes, but what precondition caused the warning to be triggered?

    Precondition?

    Some code you wrote somewhere? Some warnings you turned on for code you did not write? Don't turn on global warnings? Dont use old versions of CGI.pm? Be better programmer?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1213784]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found