SPUG:Best One-Liners and Scripts for UNIX
SPUG-list-owner
tim at consultix-inc.com
Sat Apr 19 12:37:13 CDT 2003
On Fri, Apr 18, 2003 at 06:33:02AM -0700, Brian Hatch wrote:
>
> > Ouch! That's too complicated for my "Minimal Perl" tastes.
>
<SNIP>
> I also wanted the use of the '..' operator - you're not going
> to take that away, are you?.
> --
> Brian Hatch Language, it's a virus.
Here's a version that honors the range operator.
#! /usr/bin/perl -wlna
# show_fields2c
# (C) 2003, Tim Maher www.TeachMePerl.Com
BEGIN {
# first argument contains comma-separated field numbers
# order of numbers determines order of printing fields
($fields = shift) =~ /^[\d,.]+$/g or
die "Usage: fields='2,1,3,4..7' $0 [ file ... ]";
@fields = eval " ( $fields ) "; # 5,2..4 => 5,2,3,4
}
@F or next; # skip blank lines
# Let user specify from #1
unshift @F, "(No zeroth field! first is #1)";
print "@F[ @fields ]";
-Tim
*------------------------------------------------------------*
| Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX |
| CEO, JAWCAR ("Just Another White Camel Award Recipient") |
| tim at Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com |
*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
| Watch for my Book: "Minimal Perl for Shell Programmers" |
*------------------------------------------------------------*
More information about the spug-list
mailing list