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 use
The way forward always starts with a minimal test.

In reply to Re: Script is unable to open file by 1nickt
in thread Script is unable to open file by shroh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.