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
In reply to custom args with perl -an type invocation? by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |