Re: Help Programming in Perl for File Renaming
babydoe_at_mailinator.com
Date: 02/17/05
- Next message: Martin Kissner: "Re: Problem with IO::Socket [... on Mac OS X]"
- Previous message: Mounilk: "Re: perl script to write to a text file"
- In reply to: Lynn: "Re: Help Programming in Perl for File Renaming"
- Next in thread: Brian McCauley: "Re: Help Programming in Perl for File Renaming"
- Reply: Brian McCauley: "Re: Help Programming in Perl for File Renaming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Feb 2005 22:14:54 -0800
TMTOWTDI : means it's Larry's way or the hiway.
Indicates the exit sign with a gesture, "Lynn there's the
hiway." It's not so much the turgid examples written in
archaic Perl that you've dredged up, but rather that your
algorithm is needlessly wasteful. It is wasteful because it
slurps the whole file when it only needs to read a part of
the file (and probably only the head.) Your algorithm
should exit a file on the first match.
Don't fret; there's no need to finger point at me : your
gentle narrator is also hitting the hiway, after failing to
provide a good solution. And I do realize I write Perl like
a clown, but from what I've read on this newsgroup I won't
get a good solution unless I put up a bad solution. (Is
that a usenet law?). So here is my attempt :
#!perl
use strict ;
use warnings ;
@ARGV = <*.txt> ;
my %name ;
while (<>) {
# finds last match want an early exit on first match.
$name{$ARGV} = $1 if ( /File name:\s+(\w+)/ ) ;
}
rename $_, $name{$_} for (keys %name) ;
__END__
and a sample file called a.txt :
----%<-----------start of a.txt----------------------
File name: testA
----%<-----------end of a.txt------------------------
- Next message: Martin Kissner: "Re: Problem with IO::Socket [... on Mac OS X]"
- Previous message: Mounilk: "Re: perl script to write to a text file"
- In reply to: Lynn: "Re: Help Programming in Perl for File Renaming"
- Next in thread: Brian McCauley: "Re: Help Programming in Perl for File Renaming"
- Reply: Brian McCauley: "Re: Help Programming in Perl for File Renaming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|