in reply to mkpath()

Try
mkpath("/var/tmp/log/script/",0,01777);
You need the heading 0 to make sure perl knows that you're giving it an octal value
Update: You should also follow perlplexer's advice above, and do a umask(0) before calling this. If you want it to be minimally intrusive on the rest of your program, try something like this:
sub my_mkpath { my ($path, $mask) = @_; my $ok = 1; my $save_u = umask(); umask(0); eval(mkpath($path, 0, oct($mask))); if($@) # mkpath failed! {warn "Couldn't create $path: $@"; $ok=0;} umask($save_u); return $ok; }

Replies are listed 'Best First'.
Re: Re: mkpath()
by Anonymous Monk on Apr 17, 2003 at 14:31 UTC

    This helped, but just a little bit:

    drwx-----T 2 thom thom 4096 Apr 17 16:28 script

    Thanks, Thom

Re: Re: mkpath()
by Anonymous Monk on Apr 17, 2003 at 14:58 UTC

    Thanks Improv! This works.

    But I still don't understand why I have to set the umask to oct 0...

    Anyway, at least the code works now.

Re: Re: mkpath()
by demerphq (Chancellor) on Apr 17, 2003 at 17:40 UTC

    I sort of golfed this down to the following ( I added a bit of whitespace here to make it more reable, but i get 100 chars for the block part of the sub :-)

    use File::Path; use warnings::register; sub umask_mkpath { my@c; umask((umask(shift),@c=eval{mkpath(@_)} or warnings::warnif "Err:$@")[0]); @c }

    I omitted the string to numeric conversion you were doing with oct(), because I felt the caller was more likely to know if this was needed or not, and I added the ability it set the umask (the first argument). Otherwise this should behave like mkpath(), expect that if it returns false, the error message will be in $@.

    Incidentally I did this mostly because your code reminded me of a trick i'd seen before that avoids using a temporary variable when setting an attribute on a different filehandle without changing the currently selected one.

    select((select(STDERR),$|++)[0]); # autoflush STDERR

    And I thought I might try to apply the idiom here. Anyway. :-)


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...