in reply to custom args with perl -an type invocation?
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" } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: custom args with perl -an type invocation?
by andyford (Curate) on Jun 27, 2006 at 16:41 UTC | |
|
Re^2: custom args with perl -an type invocation?
by tphyahoo (Vicar) on Jun 29, 2006 at 15:45 UTC |