Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Conditional replace

by clemburg (Curate)
on Aug 23, 2001 at 12:10 UTC ( [id://107261]=note: print w/replies, xml ) Need Help??


in reply to Conditional replace

Like this:

try.pl:

#!/usr/bin/perl -w use strict; my $count = 0; while (<>) { $count += s/foo/bar/g; print; } print "Nothing found!\n" unless $count;

Show it in action:

H:\>cat try1.txt bla blurb foo foo foo lilalu H:\>cat try2.txt bla blurb fuu fuu fuu lilalu H:\>cat try1.txt | perl try.pl bla blurb bar bar bar lilalu H:\>cat try2.txt | perl try.pl bla blurb fuu fuu fuu lilalu Nothing found! H:\>

Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-19 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found