John W. Krahn wrote:
> Rob Dixon wrote:
>> John W. Krahn wrote:
>>>          #extract year, month, day when $xfile was last modified
>>>          # eg 2008/July/9
>>>          my $dir = strftime '%Y/%b/%-d', localtime( ( lstat $xfile )[9] )
>> I hoped that was what I was looking for, but the format %- creates nothing 
>> and
>> the 'd' is simply.
> 
> It works here:
> 
> $ perl -MPOSIX -le'print strftime q[%Y/%b/%d * %Y/%b/%-d], localtime 
> 55555555'
> 1971/Oct/05 * 1971/Oct/5

C:\WINDOWS.0>perl -MPOSIX -le"print strftime q[%Y/%b/%d * %Y/%b/%-d], localtime
55555555"
1971/Oct/06 * 1971/Oct/d

C:\WINDOWS.0>perl -v

This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 25 registered patches, see perl -V for more detail)

Copyright 1987-2006, Larry Wall

Binary build 817 [257965] provided by ActiveState http://www.ActiveState.com
Built Mar 20 2006 17:54:25

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

>>>          if ( ! -e $dir ) {
>>>              mkpath [ $dir ], 0, 0750 or die "Cannot mkpath '$dir' $!";
>>>          }
>> There is no problem with calling mkpath on an already-existing directory. 
>> OTOH
>> it is documented to throw a fatal error if the path cannot be created so 
>> there
>> is no point in checking the return value (which is the number of directories
>> created by the call).
> 
> perldoc File::Path
> [ snip ]
>      ERROR HANDLING
> 
>      If "mkpath" or "rmtree" encounter an error, a diagnostic message
>      will be printed to "STDERR" via "carp" (for non-fatal errors), or
>      via "croak" (for fatal errors).
> 
> So I guess neither of us are correct.   :-)

Also from perldoc File::Path:

    If a system error prevents a directory from being created, then the
    "mkpath" function throws a fatal error with "Carp::croak". This error
    can be trapped with an "eval" block

Now I read that as meaning, "If a directory cannot be created", as I'm not sure
what a 'system error' might be. I know it carps on Windows if I try to create a
directory on a non-existent volume, like 'Q:\mydir'. But there's no such thing
as an invalid path on Unix as far as I can think.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to