Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: pattern matching -- feeling stoopit

by arturo (Vicar)
on Oct 02, 2001 at 20:50 UTC ( [id://116188]=note: print w/replies, xml ) Need Help??


in reply to pattern matching -- feeling stoopit

What's in grepfile ? The output of your grep ? (which is what, exactly? filename: [ matching line ] ? -- I'll assume that)

You need to put capturing parens in the regex for $1 to get set by a successful match. Now, assuming valid filename characters are \w (not quite true, but probably OK in the present context) what you want to match is not just the "pl" but the "." that comes before it and a bunch of word characters before that. And you probably only want the ones that are referenced within form action tags, for that matter, but let's leave that for a future refinement. So the regex you want matches "one or more word ( \w ) characters, followed by a literal ., followed by 'pl'." => /\w+\.pl/ (\w character => one or more => a literal dot => "pl" ).

Toss in the parentheses, and make the match case-insensitive (maybe necessary, maybe not), and use some nifty shorthand to put the results of $1 into a variable, and you get:

while ( my $blah = <FILE> ) { if (my ($filename) = ($blah =~/(\w+\.pl)/i) ) { print "$filename was found.\n"; } else { print "no match.\n"; } }

HTH

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://116188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found