in reply to Files and -f
my $txtfile = $prefix . ".txt"; my $txtfile1 = $prefix . "1.txt"; if ( -f $txtfile ) { # do stuff } elsif ( -f $txtfile1 ) { # do stuff } else { # no file was found }
You may want to even share whatever 'stuff' you have to do:
if ( -f $txtfile || -f $txtfile1 ) { if ( -f $txtfile ) { open(FILE, "$txtfile"); } else { open(FILE, "$txtfile1"); } # do stuff with FILE close (FILE); } else { # no file was found }
Disclaimer: Code is untested and there are probably better ways to streamline the code - aiming for readability.
Jason
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Files and -f
by mndoci (Scribe) on Dec 01, 2001 at 01:53 UTC |