Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Rename FILE to nnn-FILE

by Eimi Metamorphoumai (Deacon)
on Dec 29, 2004 at 23:02 UTC ( #418123=note: print w/replies, xml ) Need Help??


in reply to Rename FILE to nnn-FILE

Here's how I would write it, compromising between brevity and readability. (untested)
#!/usr/bin/perl use strict; use warnings; my $dir = "/home/my/files" ; chdir $dir or die "$!"; opendir(DIR,$dir ) or die "$!"; my $i = 1; for (grep { !/^\./ } readdir(DIR)) { rename $_,sprintf ('%03d-%s',$i++,$_) or warn "Couldn't rename $_: + $!"; }
I think you may be trying too hard to use perlisms (like the regexp replace). Often, it's better to just look for simpler ways to do things.

Replies are listed 'Best First'.
Re^2: Rename FILE to nnn-FILE
by uksza (Abbot) on Dec 29, 2004 at 23:10 UTC
    I think you may be trying too hard to use perlisms (like the regexp replace). Often, it's better to just look for simpler ways to do things.

    But I'm dreaming about myself as Great_Saint_YAPH_Perl_Lover ;-))

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://418123]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2016-12-03 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (56 votes). Check out past polls.