On 10/28/09 Wed Oct 28, 2009 9:37 AM, "Harry Putnam" <rea...@newsguy.com> scribbled:
> > What follows is snippet out of a more complex script and reworked to > simplify but still not seeing what causes the problem. > > I'm not sure if I've just stared at it too long or what. When I run it > I get this error: > > Use of uninitialized value in pattern match (m//) at ./match.pl > line 14. No match here > > #!/usr/local/bin/perl > > use strict; > use warnings; > > my $date_re = qr/^Date:/; > my $other_re = qr/^Date: some date/; > > if (/$date_re/ !~ /$other_re/){ > print "No match here\n" > }else{ > print "It's a match\n"; > } > The regular expression /$date_re/ by itself with no explicit variable being bound to it, e.g. $line =~ /$date_re/, will be bound to the global variable $_, which is the default variable for many Perl operators. Since at the time your if statement is executed $_ has no value, you get the error message. Comparing two regular expressions is usually meaningless. You can combine the results of two regular expression matches using logical operators: $_ = 'some string'; if( /$date_re/ && !/$other_re/ ) { # $_ matches $date_re but not $other_re } We need to know what you are trying to accomplish here. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/