develooper Front page | perl.beginners | Postings from October 2009

Not following the match problem in this simplified example

Thread Next
Harry Putnam
October 28, 2009 09:37
Not following the match problem in this simplified example
Message ID:

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 ./
    line 14.  No match here

I'm far less than skilled with the perl debugger but walking thru with
it, I tested by way or `print', if both variables have value before
the match, and of course they do.  I've looked hard for a mis-spelling
but don't see one.

Just not seeing the problem... Is it a complete misuse of `=~' ? or

I realize I could forgo the qr// compilation but should that be necessary?
In the actual script its used 20-100 times on each of thousands of
files. (the program scans only the headers of mail messages)

And shouldn't the expressions match? Or does !~ signify an EXACT
match?  I understood, it signifies a regex match in which case
`Date:' should match `Date: some date'... shouldn't it?

-------        ---------       ---=---       ---------      -------- 


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"
   print "It's a match\n";

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About