Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Exit a program if there are any matching lines?

by strat (Canon)
on Jun 27, 2006 at 09:03 UTC ( #557738=note: print w/replies, xml ) Need Help??

in reply to Exit a program if there are any matching lines?

This could look about like the following piece of code:

#! /usr/bin/perl use warnings; use strict; my $file = shift(@ARGV); unless( defined $file or -f $file ) { die "Usage: $0 filename\n"; } # unless open( my $FH, "<", $file ) or die "Error: couldn't open file '$file': $!\n"; while( defined my $line = <$FH> ) { chomp $line; if( $line =~ /something/ ) { print "Line found in $.: $line\n"; last; } # if } # while close( $FH );

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://557738]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-03-25 18:23 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (312 votes). Check out past polls.