Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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.


Comment on Re: Rename FILE to nnn-FILE
Download Code
Re^2: Rename FILE to nnn-FILE
by uksza (Monsignor) 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 lurking in the Monastery: (6)
As of 2014-09-21 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls