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"'

In reply to Re: pattern matching -- feeling stoopit by arturo
in thread pattern matching -- feeling stoopit by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.