SPUG: Re: Some changes I'd like to see in Perl

SPUG-list-owner tim at consultix-inc.com
Sat Nov 30 14:25:45 CST 2002


On Sat, Nov 30, 2002 at 01:01:14PM -0600, owner-spug-list at pm.org wrote:
> SPUG-list-owner <tim at consultix-inc.com> wrote:
> 
> > 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 = ".$$" } ...'
> > > 
> > > 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.
> 
> But I don't think that you ever actually lose any data unless you rm all those
> *.bak (or *.bak.bak or *.bak.bak.bak depending on how insistent you are at
> first :)) files.  You can always go back with something like this (from a sh):
> 

Scott,

You're quite mistaken about the data loss being unlikely; if you run 

	perl -wni.bak 's/a/b/' *.html	# should have used -n, not -p!

twice in a row, the original abc.html.bak file gets clobbered by the
(empty, after first run) abc.html file's contents, and now both abc.html*
files are empty.

Students routinely do this in my classes (some presumably think pressing
the <CR> harder the second time might make a difference 8-}), and I
accidentally do it myself periodically (for various reasons documented
in the original posting)

So this is a real problem!


> 	find . -name '*.bak' -print |
> 	while read f
> 	do b=`echo "$f" | sed 's/\.bak$//'`
> 	   mv $f $b
> 	done
> 
> Or something similar to rename all the *.bak.bak files back after the 2nd run.

You're assuming a filename pattern of *, in which case your point is
correct. But for the more general case of any arbitrary filename, as I've
indicated above, the potential of data loss remains.
 
> Personally, I would avoid assigning special meaning to any bare sequence of
> letters like that. If you want to do this, I'd go with some special character
> sequence (e.g. printf style strings like
> 
> 	perl -ni.%P
> 
> for getting a PID in there or
> 
> 	perl -ni%E
> 
> to get an emacs-style backup file sequence number in there or whatever).  That
> way you avoid turning words into alphanumerics...
> 
> 	perl -ni.INTREPID
> Scott

Good point!  I'll take your suggestion.
 

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