use of uninitialised value in pattern match (m//)

J

Jess

Hi,

I have a subscript which keeps giving this error:
Use of uninitialized value in pattern match (m//) at test_table_tk.pl
line 408.
when trying to match a $value which is specified in a Tk Listbox or a
Tk Entry box to one of a set of operators.

A snapshot of code is:
==================

# Search for operators in query
print "\n";
foreach my $this_op (qw(> < >= <=)) {
print "\nLooking for op: $this_op\n";
print "value: $value\n";
print "defined \$value: ", defined $value, "\n";
print "defined \$this_op: ", defined $this_op, "\n";
print defined $value =~ /$this_op/ , "\n";
if ( $value =~ /$this_op/ ) { # THIS IS LINE 408
print "Found: $this_op\n";
print "Before: $value\n";
($dummy,$num) = split(/$this_op/, $value);
chomp $num;
$op = "$this_op";
print "After: op=$op, num=$num\n";
$q_op = "y";
} elsif ( $q_op !~ /y/ ) {
$q_op = "n";
}
}

==================

It only gives the error on the first cycle of the foreach loop, ie.
when searching for ">". And the error only occurs when the scalar
$value doesn't have the first of the queried operators ">" in it. Ie.
If $value is ">100" no error occurs, while if it is "100" or "<100", I
get the error.

Sorry about all the debug statements, but as you see both $value and
$this_op are defined. Here is the output:

==================

Looking for op: >
value: 100
defined $value: 1
defined $this_op: 1
1
Use of uninitialized value in pattern match (m//) at test_table_tk.pl
line 408.

Looking for op: <
value: 100
defined $value: 1
defined $this_op: 1
1

Looking for op: >=
value: 100
defined $value: 1
defined $this_op: 1
1

Looking for op: <=
value: 100
defined $value: 1
defined $this_op: 1
1

==================

Sorry, this is probably rather basic, but I have looked at this and
can't quite see why it is giving this error. Thanks in advance for your
help!
 
A

Ala Qumsieh

Jess said:
I have a subscript which keeps giving this error:
Use of uninitialized value in pattern match (m//) at test_table_tk.pl
line 408.

This doesn't necessarily mean the problem is on this line. See below.
if ( $value =~ /$this_op/ ) { # THIS IS LINE 408
....

} elsif ( $q_op !~ /y/ ) {
$q_op = "n";
}

To perl, all of the above is a single statement that starts on line 408.
My guess is that $q_op is undefined, and $q_op !~ /y/ is what's causing
the warning.
It only gives the error on the first cycle of the foreach loop, ie.
when searching for ">". And the error only occurs when the scalar
$value doesn't have the first of the queried operators ">" in it. Ie.
If $value is ">100" no error occurs, while if it is "100" or "<100", I
get the error.

Yep. This pretty much confirms my guess.

--Ala
 
J

Jess

Ala said:
My guess is that $q_op is undefined, and $q_op !~ /y/ is what's causing
the warning.
Thanks. You were spot on. Now I know where to look when I get a similar
error in an extended statement.
- - Jess
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top