Arbariya has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use POSIX qw(strftime); print ("enter file name"); my $filename =<STDIN>; print $filename; if(-d $filename) { warn "File is direcrtory\n"; $filename = strftime "foo.%Y%m%d-%H%M%S.txt", localtime; print "A good filename could be '$filename'"; } else { print "File is not a directory"; #Check if file is already existing # if(-e $filename) #Overwriting an already existing file # { open(NEWFH,">$filename") || die "$filename: $!"; } }
janitored by ybiC: Balanced <code> tags around codeblock instead of HTML formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: name the file with current date and time
by Corion (Patriarch) on Mar 03, 2005 at 10:45 UTC | |
|
Re: name the file with current date and time
by holli (Abbot) on Mar 03, 2005 at 10:46 UTC | |
|
Re: problem with naming the file with current date and time
by gellyfish (Monsignor) on Mar 03, 2005 at 13:44 UTC | |
|
Re: problem with naming the file with current date and time
by Crackers2 (Parson) on Mar 03, 2005 at 20:04 UTC | |
|
Re: problem with naming the file with current date and time
by minter (Novice) on Mar 03, 2005 at 21:11 UTC |