in reply to spaces in filenames
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: spaces in filenames
by dvergin (Monsignor) on Feb 03, 2003 at 03:09 UTC | |
by fokat (Deacon) on Feb 03, 2003 at 03:23 UTC | |
by MarkM (Curate) on Feb 03, 2003 at 03:46 UTC |