Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: File::Find Usage with 2 subroutines

by Anonymous Monk
on Jun 15, 2013 at 10:05 UTC ( [id://1039099]=note: print w/replies, xml ) Need Help??


in reply to Re^2: File::Find Usage with 2 subroutines
in thread File::Find Usage with 2 subroutines

One more observation meanwhile, if I change the second find call from find(\&findb, "/pqr") to find(&findb, "/pqr"), it does enter findb sub now but the file pointed by $File::Find::name is still from the /abc/xyz folder, i.e file1.

That is to be expected. It actually calls findb() before calling File::Find::find() -- that's what the syntax means. It's not a subroutine reference but a call.

Anyway, there is no problem with your code as you've posted; I'd look into other possible problem areas such as file system permissions and the logic in the rest of your script

Replies are listed 'Best First'.
Re^4: File::Find Usage with 2 subroutines
by pnaik (Initiate) on Jun 17, 2013 at 09:36 UTC

    I found the issue, I showed wrong sequence of 'find' calls, actually the find was getting called recursively, and in that it retains the context of parent call probably. I was thinking it to be a re-entrant function, but looks like its not. This is how it looked :

    sub finda { print "In finda, $File:Find:name\n"; find (\&findb, "/pqr"); } sub findb { print "In findb, $File:Find:name\n"; } find (\&finda, "/abc/xyz");

    Anyways, now I have changed the script to have the recursive nature removed, so that the two calls happens sequentially and now its working fine. Sorry for the wrong code and very thankful for your help indeed !

        I found the issue, I showed wrong sequence of 'find' calls, actually the find was getting called recursively, and in that it retains the context of parent call probably.

      It's for this reason that we *strongly* encourage posters to show the simplest example that exhibits the bad behaviour. But I'm glad you got it all sorted. :)

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-19 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found