Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-08-27 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (382 votes). Check out past polls.