tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:
Now I have some little utilities built on "perl -an" that I would like to make more powerful by allowing flags to specify certain types of behavior. A simple example follows, where I'd like to select either letters or numbers from my piped output. Here, it doesn't work because I guess perl -an wants another file where I am trying to give it a flag.
Is there some way to do what I want with "perl -an" type invocation? Or do I have to use the diamond operator on STDOUT, like I was used to doing before I discovered perl -an?
Thanks... :)
$cat input.txt | ./anWithArgs.pl letters # should spit out lines with +a letter Can't open letters: Datei oder Verzeichnis nicht gefunden. $cat input.txt | ./anWithArgs.pl numbers # should spit out lines with +a number Can't open numbers: Datei oder Verzeichnis nicht gefunden. $cat anWithArgs.pl #!/usr/bin/perl -an my $type = shift or die "no type"; if ( $type eq 'letters' ) { print if $_ =~ /\w/; } elsif ( $type eq 'numbers' ) { print if $_ =~ /\d/; } else { print "bad type: $type" } $cat input.txt a b c d e f g 1 2 3 4 5 6 7 8 9
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: custom args with perl -an type invocation?
by Tanktalus (Canon) on Jun 27, 2006 at 15:05 UTC | |
|
Re: custom args with perl -an type invocation?
by derby (Abbot) on Jun 27, 2006 at 15:37 UTC | |
by andyford (Curate) on Jun 27, 2006 at 16:41 UTC | |
by tphyahoo (Vicar) on Jun 29, 2006 at 15:45 UTC | |
|
Re: custom args with perl -an type invocation?
by starbolin (Hermit) on Jun 27, 2006 at 19:04 UTC | |
|
Re: custom args with perl -an type invocation?
by jwkrahn (Abbot) on Jun 27, 2006 at 22:55 UTC | |
by tphyahoo (Vicar) on Jun 28, 2006 at 12:14 UTC |