Most likely, you are running without warnings and are not error-checking your results. My guess is, as you don't show how $file gets filled, that a file with the name in $file does not exist.

You will need to modify your code to track down this error, preferrably as follows:

use strict; use warnings; use Carp qw( carp ); sub get_mtime { my ($file) = @_; if (! -e $file) { carp "There exists no such file as '$file'"; return undef; }; if (! -f $file) { carp "There exists '$file' but it isn't a file."; return undef; }; my $result = (stat $file)[9]; carp $! if $!; $result; }; my @files = qw( c:\\winnt\\cmd.exe c:\\winnt\\system32\\cmd.exe c:\\winnt ); for my $f (@files) { printf "'%s' has the mtime %s\n", $f, (get_mtime($f) || 'n/a'); };

While that code is overly verbose, it should help you much with diagnosing the real cause of your error.


In reply to Re: Getting modified date for a file (Win32) by Corion
in thread Getting modified date for a file (Win32) by ciryon

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.