SPUG: Some changes I'd like in Perl

SPUG-list-owner tim at consultix-inc.com
Fri Nov 29 14:56:27 CST 2002


On Fri, Nov 29, 2002 at 09:46:08AM -0800, Yitzchak Scott-Thoennes wrote:
> 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.

I disagree, because I think options that are critical to the preservation
of file data should be very easy to use, especially by beginners.
But in the meantime the workarounds you show above could be useful.
 
> You might also take a look at the recent "edit <> files in place is
> not atomic" thread on perl5-porters.

I saw that, but it addresses a totally different (and more important)
subject.

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

Right, but at that point it would be simpler to dispense with the -n
altogether and just write your own loop, to keep from going crazy!

I admire your ingenuity for sneaking a continue block into the implicit
-n loop, but I'd like a more conventional way to accomplish this goal,
that would work with -p also.

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

** I'm delighted to see that you didn't have another wacky workaround
for this one too! 8-}

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

I do too, now that you've encouraged me to revisit this issue,
and confirm that it is indeed a pattern now (it wasn't
in Perl 4, and I guess I hadn't noticed the change in Perl5).

This proves it:

$ perl -wnaF'[\040\t]' -MO=Deparse -e 'print $F[0],"\n"'

BEGIN { $^W = 1; }
LINE: while (defined($_ = <ARGV>)) {
    our(@F) = split(/[\040\t]/, $_, 0);
    print $F[0], "\n";
}
-e syntax OK

Thanks a bunch, Yitzchak, for your helpful comments and ingenious (if
slightly deranged!) solution to the -n/continue-block problem.

Now you've got me curious to know more about you.  I know you work(ed) on
the Reefknot project, and I've seen some postings from you on p5p, but
that's it.  So where do you work, where do you live, when would you like
to share your knowledge by making a presentation to SPUG, etc.? 9-}
 
-Tim
*----------------------------------------------------------------------------*
| Tim Maher, CEO, CONSULTIX  (206) 781-UNIX; (866) DOC-PERL; (866) DOC-LINUX |
|  Ph.D. & JAWCAR ("Just Another White Camel Award Recipient")               |
|  tim at consultix-inc.com  teachmeunix.com  teachmeperl.com  teachmelinux.net |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  |
| CLASSES: Hashes and Arrays in Perl: 12/5;   Minimal Perl Programming: 12/6 |
*----------------------------------------------------------------------------*

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