Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: incrementing the file

by kcott (Archbishop)
on Feb 21, 2012 at 20:25 UTC ( [id://955381]=note: print w/replies, xml ) Need Help??


in reply to incrementing the file

There's a large number of file test unary operators which will check files for existence, size, writability and so on.

It's unclear whether you're renaming an existing file or generating a new, unique filename. If the former, File::Copy may be your best bet (there is a rename function but it has documented limitations).

-- Ken

Replies are listed 'Best First'.
Re^2: incrementing the file
by abcdefg (Acolyte) on Feb 21, 2012 at 21:10 UTC

    Hi Ken, I am generating a new file which has name of previous file and a numerical suffix which is incremented everytime... eg file 1 then file 2.....

      You can try starting with a "templated" filename and increment it until you get past all the existing files:

      my $fn = "output000"; $fn++ while -e $fn;

      At that point, you'll have a filename that is just past the last one of that pattern. Minor caveat: make sure you have enough zeroes at the end of the template - or you'll start incrementing the characters. Yes, really.

      ben@feynman:~$ perl -wle'$number = "one"; $number++ for 1..3624; print + $number' two

      :)

      -- 
      I hate storms, but calms undermine my spirits.
       -- Bernard Moitessier, "The Long Way"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://955381]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2024-04-23 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found