SPUG: Some changes I'd like in Perl
Michael R. Wolf
MichaelRunningWolf at att.net
Sat Nov 30 20:49:26 CST 2002
Tim Maher <tim at consultix-inc.com> writes:
> SPUGsters,
>
> On this Thanksgiving day, I'm giving thanks to The Larry and
> all his elves for the marvelous free invention that is Perl!
Here, here!
( or is it "Hear, hear!"? I've only heard it, not seen it in print.)
> As an added bonus, some of you, especially those that don't
> use the AWK-ish -n/-p options much, might learn about some of
To crisp it up, I'd say
awk-ish -n (or sed-ish -p)
The -n is very awk-ish and the -n is very sed-ish.
And, I'll bet Aho, Kernighan, and Weinberger don't like AWK any more
than Larry likes PERL. But I'll bet they don't have the distinction
that Perl is a language, and therefore a capitalized proper noun. And
it's all run through perl, a command, that is Perl's
compiler/interpreter.
I could be mistaken. Does the documentation refer to awk, Awk, or
AWK?
[...]
> 1) There should be a way to tell the In-Place-Editing option
> (-i) to use a unique string in composing the file-extension on
> the backup filename.
My first thought was to create a module. Before I could respond,
Yitzchak (A.K.A. Allen?) came up with a good start, then added the
sprintf(3)-like (or time(1)-like) percent arguments. I like those
ideas.
Let me add a few.
Definately have the module prevent overwrites of good data files.
Perhaps you could parameterize the module to do perform standard
backup file namings.
[I can't think of a 2-deep namespace without getting overwhelmed with
the GetOpt::* over-over-over-loaded namespace. As an added benefit,
perhaps you cold ask Ingy to use Inline::Edit. Naw, too confusing,
even if it is glamourous. You'll have to get your 15 minutes
elsewhere.]
use InlineEdit;
use InlineEdit (:numeric_version:); # use numeric increments in $^I
use InlineEdit (:PID_version:); # use PID in $^I
use InlineEdit (:truncatable:); # allow empty output to truncate
use InlineEdit (:emacs_version:); # use emacs bacup file names
use InlineEdit (:VMS_version:); # use VMS version number syntax
use InlineEdit (:native_version);
The biggest unknown at this point in my knowledge would be how to
catch the @ARGV array shifting into $ARGV. How does this happen with
respect to inline editing? Is there a way to catch this shift as the
input file is being backed up and opened? If so, these "well known"
renaming conventions, and over-write protections could be applied at
that point.
In addition, a stop_file_hook and start_file_hook function (ala emacs)
could be called to do whatever "interesting" checks or transformations
were necessary for the previous/next file. For instance, a "chmod -w"
would be great to apply to the backup file. At the very least, it
would allow the normal file system permissions to prevent the
double-shot foot shooting problem. (And yes, I've done a similar
double-shot problem. There *is* an _instinct_, in violation of my
_training_, that has me try it a second time to see if it works.
Perhaps I'm applying a hardware algorithm to software, but I grew up
in a hardware body in a hardware world gaining hardware experience.)
[...]
> Some time back, I asked Larry why there was no Awkish-FS
> variable, and he said "because my Mom says don't buy anything
> until you've felt the need for it on three separate occasions,
> and you're the first guy to ask for this!" What a guy! 8-}
Have you run a simple awk program through a2p(1) to see what Larry
would have given to his mother had she had grown up in awk-land?
[...]
> # Run following as "echo | ./scriptname"
> # To see that execution order matches statement numbers
> #! /usr/bin/perl -wln
>
> print 's2'; # I'm too lazy or deficient with VI
> # to put this statement within the BEGIN,
> # so I'll place it here to get *even earlier
> # execution* (yea, right!)
>
> BEGIN { print 's1'; }
> print 's3';
> END { print 's5'; }
>
> print 's4'; # ditto for locating this here
>
> Perl should say: "Warning: statement(s) placed before BEGIN block or
> after END block will be run within implicit loop of -n/-p"
>
FYI -- My perl doesn't give me that warning:
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 633 provided by ActiveState Corp. http://www.ActiveState.com
Built 21:33:05 Jun 17 2002
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
[...]
--
Michael R. Wolf
All mammals learn by playing!
MichaelRunningWolf at att.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list