Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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?

In reply to Re: (tye)Re2: File::Find bummers on an NFS volume. by bikeNomad
in thread File::Find bummers on an NFS volume. by petdance

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
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: (4)
As of 2021-08-05 14:36 GMT
Find Nodes?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)

    Results (44 votes). Check out past polls.