Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

A Warning Issue!

by Anonymous Monk
on Feb 19, 2008 at 16:04 UTC ( [id://668822]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks!

I have this code as part of my program generating "Use of un initialized value in pattern match (m//)", could this be because of the empty "IF" is its true?
I already initialized the variables for the regular expression to avoid the warning, Am I initializing these variables wrong?
How can I avoid the warning?!

Sample code:

my @list = (); my $lastc_33 = ''; my $lastd_34=''; my $last_33=''; ...... if( $_->{ TEST33 } eq $lastc_33 && $lastd_34 =~/8/ && $last_33 =~/00/ +&& $_->{ TEST34 } =~/7/ && $_->{ TEST33 } =~/00/ ) { } else { $lastd_34 = $_->{ TEST34 }; $last_33 = $_->{ TEST33 }; push (@list, $_); }


Thank you!!!

Replies are listed 'Best First'.
Re: A Warning Issue!
by jrsimmon (Hermit) on Feb 19, 2008 at 16:44 UTC
    I strongly suspect that the uninit'd var perl is complaining about is $_->{TEST34}. I suggest checking your vars to be sure.
    use Data::Dumper; my @list = (); my $lastc_33 = ''; my $lastd_34=''; my $last_33=''; ...... print Dumper $_->{TEST33}; print Dumper $lastc_33; print Dumper $lastd_34; print Dumper $last_33; print Dumper $_->{TEST34}; if( $_->{ TEST33 } eq $lastc_33 && $lastd_34 =~/8/ && $last_33 =~/00/ +&& $_->{ TEST34 } =~/7/ && $_->{ TEST33 } =~/00/ ) { } else { $lastd_34 = $_->{ TEST34 }; $last_33 = $_->{ TEST33 }; push (@list, $_); }
    If that still doesn't show you where the warning is being generated, break up your if statement so that you can see which piece of it is generating the error.
Re: A Warning Issue!
by thezip (Vicar) on Feb 19, 2008 at 16:38 UTC

    Since you've explicitly initialized a few of the variables, then only the remaining ones are the potential causes for the warnings, namely $_->{ TEST34 } and $_->{ TEST33 }.

    Perhaps you might want to check their values prior to the IF statement to ensure they are what you think they are. If either is not initialized, then just don't execute the IF statement.

    BTW, that's a fairly complicated piece of logic there. Maybe you might want to break it up into smaller, logical chunks? That way, you'll have a better idea of what you were trying to do six months down the road.


    Your wish is my commandline.
      That's why I am confused, I my head the IF should be doing this check, how would I check otherwise?

        At the risk of adding more bulk to your code, try this check first, as well as one for $_-> { TEST34) }.

        if ($_->{ TEST33 } ) { <your previous code here ...> }

        Your wish is my commandline.
Re: A Warning Issue!
by olus (Curate) on Feb 19, 2008 at 16:11 UTC

    Where does $_ come from? Are those keys defined in the hash it references?

      Yes it is!
      $data = (); $sql = sprintf $sql_fmt, $account->[$i]{ 'ACCOUNT#' }; $data = exec_select( $sql ); foreach (@$data) { ....

        From this snippet and the first one I can understand that data is an array that references hashes. This last snippet shows that data may be defined with the result of the call to exec_select. Still, that shows no guarantee that the hashes in data have the keys $_->{TEST34} and $_->{TEST33}. You may be assuming that they are present, but they are not.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found