Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am using the following code in a script
sub DESTROY { my $self =shift; local $@; if($self->{dir} and -d $self->{dir}) rmtree $self->{dir}; } }

I am getting the following warning.
cannot stat initial working directory for cannot stat initial working directory for /tmp/A123/B111
How can I ignore this warning message and continue the work?

Replies are listed 'Best First'.
Re: how to suppress warning from rmtree command
by blue_cowdawg (Monsignor) on Aug 19, 2011 at 15:30 UTC
        How can I ignore this warning message and continue the work?

    eval { mkpath($dir) }; if ($@) { print "Couldn't create $dir: $@"; # leave this out if you want si +lence } # untested code. should not be used to control laser brain surgery sy +stems


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
      The OP is not creating a directory, but removing it. Maybe the error is due to not being able to create the directory in the first place, but it also may be due to the the directory being removed while it's the current directory...but there's not enough code above to tell. And eval doesn't suppress warnings, it suppresses errors. Or did I miss the OP changing beyond recognition after you posted your answer :-)
Re: how to suppress warning from rmtree command
by runrig (Abbot) on Aug 19, 2011 at 15:46 UTC
    Apparently rmtree needs to stat the initial working directory (maybe so that it can chdir back to it when finished). Do you know of some some reason that it can't? Does the directory still exist, etc. (it would maybe help if $! was included in the error message)? Can you chdir to a directory that can be stat'd before executing rmtree?