in reply to Replacing a search/not found pattern with a word

As a one-liner:

c:\test>perl -ple"s[^(.*)$]{ $1 =~ m[DOG] ? 'DOG' : 'Not found' }e" ju +nk.dat DOG DOG Not found DOG Not found DOG DOG DOG DOG

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Replacing a search/not found pattern with a word
by ikegami (Patriarch) on Mar 23, 2008 at 04:33 UTC
    Simpler:
    perl -nle"print /(DOG)/ ? $1 : 'Not found'"
    Or if you wanted to keep the -p:
    perl -ple"$_ = /(DOG)/ ? $1 : 'Not found'"

      I can shave a couple of strokes off of that:

      perl -lpe'$_=/DOG/?$&:"Not found"'