
FishMonger
Veteran
Jun 16, 2012, 6:50 AM
Post #3 of 4
(709 views)
|
|
Re: [gerble1000] could somebody explain why this dont work please
[In reply to]
|
Can't Post
|
|
my $date_string = localtime; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $year += 1900; $mon += 1; Use the strftime function from the POSIX module to assign your date string. It is much easier and cleaner.
my $date = strftime("%d.%m.%Y", localtime);
my $location = "archive\$mday.$mon.$year"; Use a forward slash instead of the backslash and use the var that was already assigned the datestamp.
my $location = "archive/$date"
open(F, '>>:utf8', $location); print F "my string"; 1) use a lexical var for the filehandle instead of the bareword 2) ALWAYS check the return code of an open call to verify it was successful and take proper action if it wasn't 3) Why are you using printf without specifying a format? It's better to use print if you don't need the printf formatting
open my $fh, '>>:utf6', $location or die "failed to open '$location' in append mode: <$!>"; print $fh "my string";
|