There's a space in the value of $date_time so your open() call thinks the filename is e:\scripts\OutageNodes\maintenanceMode_201586 and that you are passing 9:45:1.log as another argument. (Update: Problem is the colons, not the space as pointed out by marinersk, I was guessing at the exact cause of the error.)
Just use DateTime.
use DateTime; my $dt = DateTime->now; my $file = 'foo_' . $dt; print $file;
Prints:
foo_2015-08-06T17:05:17
Note that this gives the datetime in ISO-standard format, which is good for later use elsewhere. Note also that now() returns a datetime in UTC timezone, so if you want your local time just use
$dt = DateTime->now( time_zone => 'local' );
If you can't have colons in the file name, just specify a different format:
my $dt = DateTime->now(time_zone => 'local')->strftime("%Y-%m-%d-%k-%M +-%S");
Prints:
2015-08-06-10-42-18
Finally note that $dt is a DateTime object but if you use it as a string it prints the datetime so you can be lazy.
Upate: showed DateTime useIn reply to Re: Script is unable to open file
by 1nickt
in thread Script is unable to open file
by shroh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |