File::Find doesn't go down thru directory

Discussion in 'Perl Misc' started by cmic, Dec 13, 2007.

  1. cmic

    cmic Guest

    Hello

    Instead of mixing shell scripts and Perl, I prefer to do all the job
    of the command find (recursion) and other piped commands with Perl.
    However, the snippet below doesn't print any file under the current
    directory.
    The commented line (print "Result...) give the right information, if
    uncommented, of \
    course.

    Any hint ? What do I
    miss ,
    --
    michel marcon aka
    cmic
    Sysadmin.

    #!/usr/local/bin/
    perl
    use
    strict;
    use
    warnings;
    use
    File::Find;

    find(\&wanted,
    ".");

    sub wanted
    {
    my $file=
    $File::Find::name;
    # print "Result $file,
    "\n";
    if (-f $file )
    {
    print $file,
    "\n";
    }
    }
     
    cmic, Dec 13, 2007
    #1
    1. Advertisements

  2. cmic> sub wanted
    cmic> {
    cmic> my $file=
    cmic> $File::Find::name;
    cmic> # print "Result $file,
    cmic> "\n";
    cmic> if (-f $file )
    cmic> {
    cmic> print $file,
    cmic> "\n";
    cmic> }
    cmic> }

    Hint: $File::Find::name will look like ./foo/bar, but you'll be cd'ed into
    "./foo" already, so there's no ./foo/bar below ./foo.

    If you're *in* "wanted", use $_.
    If you're *after* "wanted", use $File::Find::name.

    Don't confuse the two. They both have their purpose.

    print "Just another Perl hacker,"; # the original
     
    Randal L. Schwartz, Dec 13, 2007
    #2
    1. Advertisements

  3. cmic

    cmic Guest

    On 13 déc, 23:58, (Randal L. Schwartz) wrote:
    ........
    OK I dig it now
    Thx Randal. Sorry for the unformatted post..
     
    cmic, Dec 13, 2007
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.