SPUG: Some changes I'd like in Perl

Yitzchak Scott-Thoennes sthoenna at efn.org
Fri Nov 29 11:46:08 CST 2002


On Thu, 28 Nov 2002 09:09:13 -0800, tim at consultix-inc.com wrote:
>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.

Right now, you can do:

perl -ni -we'BEGIN { $^I = ".$$" } ...'

Or given a PidBackup.pm:
# Make inplace edit backup contain our pid.  If a backup extension is
# set and contains '$$', the actual pid will be substituted.
# Otherwise, the extension will be set to "." followed by our pid.
BEGIN { 
    if (!defined $^I) { warn "PidBackup used without -i switch" }
    else { $^I =~ s/\$\$/$$/ or $^I = ".$$" }
}
1;

perl -MPidBackup -ni -we' ... '

Given that there is a way to do this, I'd hesitate to add a special
case for "PID", even at the cost of making it much harder to type.
YMMV.

You might also take a look at the recent "edit <> files in place is
not atomic" thread on perl5-porters.

>* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
>2) Perl programmers should have the ability to define a continue
>block within -n programs, or override the default continue
>block within -p programs.

You can actually do this.  Try:
perl -wlne'$_ ne "" or next; print } continue { print "Finished with line $." '

That is, you have to say -e'foo } continue { bar' where foo is the body of the
loop and bar is the contents of the continue block.

>* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
>3) There should be a variable that allows dynamic setting of the field
>separator (used by -a) during execution.

This should be done.  I'd suggest $^FS.

>(Another great feature that's obviously missing is
>the ability to set the field separator to a *regex*, but at
>least we have a (manual) workaround for that using split.)

I think it is a regex.

>* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
>4) Perl needs a warning for misplaced statements that will be run
>within the implicit loop of -n/-p.
>
>A warning is needed for the common newbie mistake, where
>statement(s) are placed above the BEGIN block, or below the END
>block, in a program using the -n (or -p) option.

I've never seen this mistake, so have no opinion.

>* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
>5) There should be a better warning when the -e option is used
>without a corresponding argument on the shebang line.

>A more useful warning than any of the above would be something like:
>
>	The -e option requires a following argument that contains 
>	a perl program at /tmp/shebang line 1.

Sounds good.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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