Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by bikeNomad (Priest)
on Aug 01, 2001 at 22:58 UTC ( #101480=note: print w/replies, xml ) Need Help??


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

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2021-05-13 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (134 votes). Check out past polls.

    Notices?