in reply to use regex match from file grep

What do you want it to be? Grep loops over all of the input, so the only thing that makes sense (to me) is the last match:

my $last_match; if ( grep { /^tag\: (.*)$/ and $last_match = $1 and 1} <FILE> ) { print "Found tag: $last_match\n"; }

more likely you want all matches:

while (<FILE>) { next unless /^tag\: (.*)$/; print "Found tag: $1\n"; }

edit: or even

print map /^tag\: (.*)$/ ? "Found tag: $1\n" : (), <FILE>;

Hope this helps,
Joost.

Replies are listed 'Best First'.
Re^2: use regex match from file grep
by rsiedl (Friar) on Jun 11, 2004 at 12:05 UTC
    Thanks Joost.

    Example 1 does the trick :)

    Cheers,
    Reagen