SPUG:Best One-Liners and Scripts for UNIX

Bob Hiltner bob at hiltners.com
Sat Apr 19 15:22:59 CDT 2003


Seeing all the one-liners (not this post particularly) brings to mind one of
the great things about PERL.  You don't need code obfuscation utilities for
IP protection.  It's done automatically at the source code level! ;^)
What's the other way to say it?  Write Once, Read Never?

On a more serious note... that is one of the things that does make me shy
away from getting into perl in a serious way... too much magic.  This stuff
that (perhaps) makes sense to the initiated and the high priests is like
reading binaries to the casual perler.   I've been doing more .Net stuff for
a while, and I feel the understandibility of perl quickly slipping away when
I (try to) read stuff like this.  I don't see the same issues at all when I
get away from, say, C for a while.  Is that just the idioms of the language?
There's plenty of cryptic stuff available in C too, but I don't see it much
in real code.

So what's the balance?  One can be very efficient in use of precious memory
at the expense of the sucker who has to follow the code, or one can write
verbose cobol, and the follower can settle in for reading a nice long
bedtime novel.  So the question is, if writing clear and readable perl is
possible, which I believe it is, is it just my perception that the idioms
are toward opacity over readibility?  Isn't that a bit of a shame?  How do
you get to the inherent coolness of the language without all the unreadable
magic?

It might just be me.  I tend to have the same problem with regexes, which I
think are the coolest thing going.  If you don't use em for a while, it's a
bit of retraining each time.  It'd be nice to have that kind of power with
some better readibility.

    -Bob

----- Original Message -----
From: "SPUG-list-owner" <tim at consultix-inc.com>
To: "Brian Hatch" <spug at ifokr.org>
Cc: "Tim Maher" <tim at consultix-inc.com>; "David Dyck"
<david.dyck at fluke.com>; <spug-list at pm.org>
Sent: Saturday, April 19, 2003 10:37 AM
Subject: Re: SPUG:Best One-Liners and Scripts for UNIX


> 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 ]";






More information about the spug-list mailing list