I have a statement in Perl like
if (($hh, $mm) = ($info{$item}{$p_expectedtime} =~ /(\d+):(\d+)/))
but when compiling, I get the message:
Use of uninitialized value in pattern match (m//)
Tried to add a define() like
if (define($hh, $mm) && ($hh, $mm) = ($info{$item}{$p_expectedtime} =~ /(\d+):(\d+)/))
which is incorrect.
Here's your code:
if (($hh, $mm) = ($info{$item}{$p_expectedtime} =~ /(\d+):(\d+)/))
And here's the error message:
Use of uninitialized value in pattern match (m//)
Note, that the error says the uninitialised value is in the pattern match, not the assignment, so we can eliminate the first piece of the code from our investigations, leaving us with:
$info{$item}{$p_expectedtime} =~ /(\d+):(\d+)/
If it were $item or $p_expectedtime that were uninitialised then the error would talk about "uninitialised value in hash element", so it's not those that are undefined either.
No, the uninitialised value is the value that you're comparing with the regex. It's the value in $info{$item}{$p_expectedtime}.
Tried to add a
define()
Two problems here. Firstly, you're checking $hh and $mm which we've already eliminated from our investigations. And, secondly, the function you're looking for is actually called defined() (with a 'd'). So you might want something like:
if (! defined $info{$item}{$p_expectedtime}) {
warn "\$info{$item}{$p_expectedtime} is undefined\n";
} else {
# Original code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With