Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

how to use find() options

by ypreisler (Novice)
on Apr 17, 2024 at 16:16 UTC ( [id://11158915]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

i am not able to follow symbolic links when using the find() command. it says on the manual that the 'follow' or 'follow_fast' option should be used but i don't understand how to use it together with the '\&wanted' routine -

use File::Find; find(\&wanted, @directories); find(\%options, @directories);
thanks a lot, Yaron.

Replies are listed 'Best First'.
Re: how to use find() options
by davido (Cardinal) on Apr 17, 2024 at 16:57 UTC

    find( { wanted => \&wanted_function, follow => ..., }, @directories );

    It's there in the documentation; In the case of passing in an "options" hashref, the wanted function is one of the key/value pairs in that hashref.


    Dave

      Hi Dave, thanks for the reply. i did not understand the "follow => ...," part. what should the "...," section include? thanks, Yaron.

        The SYNOPSIS section from the documentation for the module shows exactly how to do what you're asking in this thread, and shows an example of what follow should contain:

        Here's the third example in the SYNOPSIS section:

        use File::Find; find({ wanted => \&process, follow => 1 }, '.');

        Dave

        A true value if you want the option to take effect, a false value otherwise. See follow.


        🦛

        What part of "there in the documentation" don't you understand? Learning to use documentation is an important part of learning to write code, or indeed doing many things in life.

        Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re: how to use find() options
by Fletch (Bishop) on Apr 18, 2024 at 00:50 UTC

    Its not a direct answer but if you know how to get the find command to do what you want the find2pl program that comes with Perl can be useful getting sample code. Might also look at File::Find::Rule which has a bit nicer api.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: how to use find() options
by eyepopslikeamosquito (Archbishop) on Apr 19, 2024 at 03:36 UTC

    Hi Yaron,

    You've already received some excellent answers!

    In case it helps you improve your Perl skills, I've cobbled together File::Find References. After you've had time to read and digest them, please feel free to post your early attempts at using File::Find here for feedback.

    If you put in the effort to create a SSCCE, you are certain to receive lots of useful advice that will improve your Perl skills.

    👁️🍾👍🦟
Re: how to use find() options
by ForgotPasswordAgain (Priest) on Apr 17, 2024 at 16:55 UTC
    %options has a wanted option.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11158915]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-05-20 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found