#!/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 = $_ = ){ 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) -o (butler o_pens the door) -s (bouncer s_huts the door) -l (bellhop is l_ast through the door) "; die"\n"; } __END__ apple banana pear peach grape orange