Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Rename FILE to nnn-FILE

by Eimi Metamorphoumai (Deacon)
on Dec 29, 2004 at 23:02 UTC ( [id://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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://418123]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-23 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found