Update: Thanks to MarkM for pointing out that split() accepts a scalar as its first argument just fine, provided you escape the \'s

I think the problem lies in your call to split(). You should pass a pattern as its first argument, but instead you're passing a scalar. Later I provide a proper example. This is a test of utime() on my system, just so we know this is not culprit.

bash-2.05a$ touch "my file"
bash-2.05a$ ls -l "my file"
-rw-r--r--  1 lem  staff  0 Feb  2 21:28 my file
bash-2.05a$ sleep 60; perl -e 'print utime(undef, undef, "my file"), "\n";'
1
bash-2.05a$ ls -l "my file"
-rw-r--r--  1 lem  staff  0 Feb  2 21:29 my file

Also, you should be checking the return value of utime(). When it fails, returns a false value. You could then use the special variable $! to see a (hopefully) meaningful error message. See perlvar for more info on this variable.

Your code is otherwise fine (I guess) but I would like to offer a shorter and untested alternative...

open(CSV, "/tmp/doctime.txt") or die "Failed to open CSV: $!\n"; while (my $line = <CSV>) { my @val = split(/,/, $line, 2); unless (utime $val[0], $val[0], $val[1]) { warn "Failed to utime $val[1]: $!\n"; } } close CSV;

++ for -w, but you should also use strict.

Best regards

-lem, but some call me fokat


In reply to Re: spaces in filenames by fokat
in thread spaces in filenames by ironpaw

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.