Although I like perl's command line switches for one-liners, I question their value inside of scripts (maybe my concept of best practice is wonky). The only one I ever really used was -w but I've given that up for use warnings;. For the example given, I don't see any need for the -a and you can avoid the -n by just coding explicity:
While the -an and the BEGIN blocks highlight TIMTOWTDI, I find the explicit looping makes the script easier/quicker to understand and will be better suited if/when you shift to argument parsing modules.#!/usr/bin/perl our $type ||= shift or die "no type"; while( <> ) { if ( $type eq 'letters' ) { print if $_ =~ /[[:alpha:]]/; } elsif ( $type eq 'numbers' ) { print if $_ =~ /\d/; } else { print "bad type: $type" } }
In reply to Re: custom args with perl -an type invocation?
by derby
in thread custom args with perl -an type invocation?
by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |