Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

(tye)Re2: File::Find bummers on an NFS volume.

by tye (Sage)
on Aug 01, 2001 at 22:12 UTC ( #101464=note: print w/replies, xml ) Need Help??

in reply to Re: (tye)Re: File::Find bummers on an NFS volume.
in thread File::Find bummers on an NFS volume.

Perhaps I was thinking of some module other than File::Recurse. Darn.

How would it transfer to the user's code if it didn't callback?
Iterators, of course.

For any readers who aren't familiar with the concept: I find bikeNomad's question similar to "But how can we let the user run a section of code once for each line of an input file without requiring them to write callbacks?"

Perl is full of iterators. File globbing, line reading, regex matching, and iterating over an array or other list are all common examples of things that are often done in Perl using interators. And this is because callbacks suck. (:

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re2: File::Find bummers on an NFS volume.

Replies are listed 'Best First'.
Re: (tye)Re2: File::Find bummers on an NFS volume.
by bikeNomad (Priest) on Aug 01, 2001 at 22:58 UTC
    I don't see much of a difference between these idioms in Perl:
    # iterator sort { $a cmp $b } @array; # callback sub myFunc { $a cmp $b } sort myFunc @array;
    It's interesting you mention this. My Algorithm-Diff module uses callbacks, in part because the original module by Dominus did, and in part because that seemed like a good thing to do. There are, in fact, about 6 callbacks that could be specified. A couple are there to handle comparison and hashing of user-defined data types (since everything in Perl isn't an object). The rest of them are there so that user code can be run while traversing the input sequences. This turns out to be pretty useful.

    I'm re-doing this module in Ruby, and am re-considering the interface in the process.

    I ended up with the various diff functions in a class; if someone wants to override comparison behavior, they just re-define a method or two (Ruby lets you do this on a per-object basis; for the equivalent in Perl you can use my Class::Prototyped module). I wonder if that would be a better interface in Perl. You'd just override the methods you cared about:

    package MyDiff; @MyDiff::ISA = 'Algorithm::Diff'; sub keyGen { ... } sub compare { ... } sub match { ... } sub skip_a { ... } package main; my $diff = MyDiff->new(); $diff->traverse_sequences(\@a1, \@a2);

    Do you think that this is a better idiom than explicit callbacks?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2021-06-12 18:38 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (53 votes). Check out past polls.