Jun 16, 2012, 6:50 AM
Post #3 of 4
Re: [gerble1000] could somebody explain why this dont work please
[In reply to]
Use the strftime function from the POSIX module to assign your date string. It is much easier and cleaner.
my $date_string = localtime;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon += 1;
my $date = strftime("%d.%m.%Y", localtime);
Use a forward slash instead of the backslash and use the var that was already assigned the datestamp.
my $location = "archive\$mday.$mon.$year";
my $location = "archive/$date"
1) use a lexical var for the filehandle instead of the bareword
open(F, '>>:utf8', $location);
print F "my string";
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";