Welcome to the monastery, Dervish!
As suggested, you should give a minimal piece of code that will compile and run and produce the issue you're having. In case you're not aware (though you've likely guessed), the message you're seeing is a non-fatal warning, which means you're invoking the script with -w or putting use warnings; at the top. This is usually (always?) a good thing to do.
What this particular warning is telling you is that you're attempting to use a regular expression against an undefined variable.
Something like the following, for example, would produce a similar warning to what you're seeing.
use warnings;## good line to have. use strict; is also prudent
$x=undef; ## I explicitly set it to undef here]
## even if I commented this, though, I'd have
## the same warning
($s)=$x=~m/regex/; ## $x is undefined, and produces warning
print $s; ## presumably, I wanted $s for something
You should definitely look at the line number suggested by the warning. | [reply] [d/l] [select] |
Run-time warnings and errors in the expression of an elsif condition will bear the line number of the start of the if statement.
| [reply] [d/l] [select] |
use strict;
use warnings;
my $tmpf = 'farms';
my %factories = (farms => "Farmer Brown's");
print "$tmpf\n"; # prints 'farms'
print keys( %factories), "\n"; # 'farms' is one of them.
print "Is defined" if ( defined $factories{ $tmpf});
Prints:
farms
farms
Is defined
How is it different from your code snippet that generates an error message that on the face of it has nothing to do with the snippet? Perhaps you could modify my snippet to demonstrate your error? You could also read I know what I mean. Why don't you?.
DWIM is Perl's answer to Gödel
| [reply] [d/l] [select] |
#!/usr/bin/perl
use strict;
use warnings;
my %factories = ( 'farms' => 'horses');
my $tmpf = 'farms';
my $match = "horses on the farm!";
print "$tmpf\n"; # prints 'farms'
print keys( %factories), "\n"; # 'farms' is one of them.
if ( defined $factories{$tmpf} ) {
print "yay!\n" if $match =~ m/$factories{$tmpf}/;
}
prints:
farms
farms
yay!
to ask a question is a moment of shame
to remain ignorant is a lifelong shame
| [reply] [d/l] [select] |
| [reply] [d/l] [select] |
Maybe so. Though we don't now by now, what the warning actually refers to.
The OP is not very clear about this, but the consensus in the replies seems to be that the offending operation takes place inside a block guarded with:
if ($factories{$tmpf})
If $factories{$tmpf} had been undef, perl would not have reached the inside of that conditional block.
Of course this is also pure guesswork, unless the OP succeds in posting some code to reproduce the problem. :-D
| [reply] [d/l] [select] |
| [reply] |