Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: 'unlink' seems to not work correctly ...

by merlyn (Sage)
on Dec 02, 2009 at 19:55 UTC ( #810665=note: print w/ replies, xml ) Need Help??


in reply to 'unlink' seems to not work correctly ...

Your $File::Find::name contains the whole path, but you are likely chdir'ed into the lowest directory during wanted.

Either unlink $_ within wanted, or wait until wanted is finished and do it all afterward.

-- Randal L. Schwartz, Perl hacker

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.


Comment on Re: 'unlink' seems to not work correctly ...
Select or Download Code
Re^2: 'unlink' seems to not work correctly ...
by codeacrobat (Chaplain) on Dec 02, 2009 at 21:04 UTC
    ... or unlink on the fly, with the no_chdir option. With no_chdir $File::Find::name and $_ are equivalent.
    find( {wanted => \&wanted, no_chdir=>1}, @directories ); sub wanted { my $wanted = -l && !-e; push @msgs, $_ and $counter++ if $wanted; return if $param{test} or !$wanted; unlink or croak "Warning: couldn't unlink '$_' :$OS_ERROR\n"; return; }
    Update Refactored wanted function.

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
      That is, if you're willing to pay the performance penalty for no_chdir, and in this case, it seemed unwarranted, since the workaround was so easy.

      -- Randal L. Schwartz, Perl hacker

      The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

        performance penalty?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://810665]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-09-22 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls