Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: problem printing message if search item is not found

by omega_monk (Scribe)
on Jun 20, 2005 at 15:37 UTC ( [id://468391]=note: print w/replies, xml ) Need Help??


in reply to Re: problem printing message if search item is not found
in thread problem printing message if search item is not found

Thought it might be helpful to see a rewrite of the code. ;)

Just cleaned up a bit, and added use strict; and use warnings; and a little bit of error handling.
#!/usr/bin/perl use strict; use warnings; my $fsearch = 'file.txt'; open (TEXTFILE, 'c:/perl_programs/' . $fsearch) or die "CAN'T OPEN $fs +earch: $^E\n"; print "Enter a string to search for: "; chomp (my $search = <STDIN>); my @line = <TEXTFILE>; my $count = 0; foreach (@line){ $count++; if ($_ =~ /$search/i) { print "\nLine that matched <$search> found on line #$count\n"; print "$_\n"; } } if (!$count) { print "\nsubstring <$search> NOT found\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2025-04-20 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.