Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Checking for existing filename before renaming file

by martymart (Deacon)
on Feb 14, 2003 at 16:04 UTC ( [id://235297]=note: print w/replies, xml ) Need Help??


in reply to Checking for existing filename before renaming file

you could use a file test operator to check that files exist before they are overwritten. Type perldoc perlfunc at a command prompt and look in the section "Alphabetical List of Perl Functions" to see the full list of file test operators.
print "Save data to what file?"; $filename=<STDIN>; chomp $filename; if (-s $filename){ warn "$file contents will be overwritten!\n"; warn "$filename was last updated ", -M $filename, "days ago.\n"; }
-M =returns the age (in days)
-s =returns the size of the data (in bytes)

Martmart

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-09-07 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.