perl - Checking if filename exists in current directory -


i have script trying modify depending on location executed from, checking see if there file name regression_user.rpt , if so, make new file called regression_user1.rpt. i've found solutions im not sure how change want.

what have following:

my $filename = 'c:\temp\test.txt'; if(-e $filename){    //create file new name    print("file $filename exists\n"); }else{    //create base file    print("file $filename not exists\n"); } 

except, path $filename variable. there way incorporate execution location variable check?

the purpose of make sure dont overwrite existing files (has happened 1 many times).

if execution location mean current work directory, need following:

my $filename = 'test.txt'; 

if execution location mean directory in script being executed found, can use following:

use findbin qw( $realbin );  $filename = "$realbin/test.txt"; 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -