Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: File::Find incompatible with OO perl?

by ysth (Canon)
on Feb 09, 2004 at 16:48 UTC ( [id://327661]=note: print w/replies, xml ) Need Help??


in reply to File::Find incompatible with OO perl?

Just wrap your method call in a sub:
find(sub {$obj->found}, $directory);

Replies are listed 'Best First'.
Re: Re: File::Find incompatible with OO perl?
by vaevictus (Pilgrim) on Feb 09, 2004 at 17:08 UTC
    This is almost good equivalent to my wanted subroutine. However, I'm still losing the contents of $_; I guess i just have to use  find(sub{$obj->found($_)},$directory); Thanks!
      Are you sure you mean $_ and not (after first shift) $_[0]? wanted doesn't get any parameters, so what you have above is only correct if your found() expects the filename via a parameter, not $_.

      This works for me:

      $ perl -MFile::Find -we'$obj=bless []; sub found { print "looking at $ +_\n" } > find(sub {$obj->found}, "pbed/fooble")' looking at . looking at a looking at b looking at c

        wanted(), being the non-OO answer, is supposed to recieve a file name via $_. Check the perldoc, it backs me up. Not that I'm saying its the best way that this should have been done, but find is supposed to produce 3 elements for your called subroutine:

        • $File::Find::name => Path + Filename.
        • $File::Find::dir => Path
        • $_ => Filename

        I'm not sure whether it clashes or agrees with your statement. Regardless, I'm getting the data as I think it works, like this:

        Calling:

        find(sub{$obj->found($_)},"dir");

        Called:

        sub found { my $self=shift; my ($full_name, $file_dir,$file_name) = ($File::Find::name,$File::F +ind::dir,@_); }

        Thanks again!!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found