Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Finding part of a file

by mkmcconn (Chaplain)
on Dec 05, 2001 at 14:22 UTC ( [id://129559]=note: print w/replies, xml ) Need Help??


in reply to Finding part of a file

Bored waiting for installs to finish. Thanks for an entertaining question:

#!/usr/bin/perl -wl # gate : a printer gate use strict; use Getopt::Std; use constant OPEN => 1; use constant SHUT => 0; use vars qw($opt_p $opt_o $opt_s $opt_b $opt_l); local ($opt_p, $opt_o, $opt_s, $opt_b, $opt_l); getopts(qw(pb:o:s:l:)); unless ($opt_o or $opt_b ){ usage() unless $opt_p; } if (@ARGV){ open FH, $ARGV[0] or die $!; } else { *FH = \*DATA ; } my $enter = $opt_p ? $opt_p : SHUT; # breeze my $breach = $opt_b ? $opt_b : 'the burgler breaks in'; my $open = $opt_o ? $opt_o : 'the butler opens the door'; my $shut = $opt_s ? $opt_s : 'the bouncer shuts the door'; my $last = $opt_l ? $opt_l : 'the bellhop is last through the door +'; while (my $door = $_ = <FH>){ chomp ($door,$_); exit if $door =~ /^$shut$/; # bouncer $enter = OPEN if $door =~ /^$breach$/; # burgler $enter and print; $enter = OPEN if $door =~ /^$open$/; # butler exit if $door =~ /^$last$/; # bellhop } sub usage { print "The door is shut\n", "$0 -p (p_neuma is Greek for 'breeze') -b (burgler b_reaks in) <item> -o (butler o_pens the door) <item> -s (bouncer s_huts the door) <item> -l (bellhop is l_ast through the door)<item> "; die"\n"; } __END__ apple banana pear peach grape orange

$ gate -o banana -s grape
pear
peach
update2
$ gate -o apex -s apple ./words
apexed
...
applausively
mkmcconn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-28 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found