Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: When should a wheel be reinvented

by tachyon (Chancellor)
on Jun 30, 2004 at 03:20 UTC ( #370675=note: print w/replies, xml ) Need Help??


in reply to When should a wheel be reinvented

The patch is pretty trivial (minimal testing but don't see why it should not be stable). The value of $_ is saved and restored so you can change/use it in &wanted with impunity. Note as we are passing 3 values to the &wanted every time there will be a slowdown but this is probably (speculation) trivial compared to iterating over the directory tree.

$ diff Find.pm FindPatch.pm 1c1 < package File::Find; --- > package File::FindPatch; 394c394 < { &$wanted_callback }; # protect against wild "next" --- > { my $save=$_; &$wanted_callback($save,$name,$dir); $_=$ +save }; # protect against wild "next" 450c450 < { &$wanted_callback }; # protect against wild "next" --- > { my $save=$_; &$wanted_callback($save,$name,$dir); $_=$ +save }; # protect against wild "next" 495c495 < { &$wanted_callback }; # protect against wild "next" --- > { my $save=$_; &$wanted_callback($save,$name,$dir); $_ +=$save }; # protect against wild "next" 519c519 < { &$wanted_callback }; # protect against wild +"next" --- > { my $save=$_; &$wanted_callback($save,$name,$ +dir); $_=$save }; # protect against wild "next" 525c525 < { &$wanted_callback }; # protect against wild "nex +t" --- > { my $save=$_; &$wanted_callback($save,$name,$dir) +; $_=$save }; # protect against wild "next" $

cheers

tachyon

Replies are listed 'Best First'.
Re^2: When should a wheel be reinvented
by theorbtwo (Prior) on Jun 30, 2004 at 05:13 UTC

    All of your my $save=$_; ... $_=$saves can be replaced by local $_=$_; ...


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      Good point, not that it makes much practical difference.

        Yes, it does; wanted is AFAIK allowed to bail out with an exception (die) or loop operator (next, last, redo) or even goto.

        Update: never mind; obviously if you leave File::Find::find, that no longer cares if you modify $_.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2019-10-17 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?