Just to play Devil's Advocate:

What benefit stands to be gained to using $arrayobj->find($key) as opposed to mapping the list to a hash and testing a key?

It's not hard to imagine an implementation of $array->contains($key) (instead of "find", which I would hate) using grep or List::MoreUtil's indexes (which is XS, and therefore pretty fast). Examples:

## discover if an array contains a value, using grep sub contains { ## usage: $bool = $array->contains( $value ) # is $value in $array +obj? ? my ($self, $val) = @_; my $r_array = $self->{data}; # assume this contains the array ## for example, assume values are strings my $cnt = grep { $_ eq $value } @$r_array; return $cnt ? 1 : 0; }
## discover if an array contains a value, using List::Util::indexes; sub contains { ## usage: $bool = $array->contains( $value ) # is $value in $array +obj? ? my ($self, $val) = @_; my $r_array = $self->{data}; # assume this contains the array ## for example, assume values are strings my $cnt = List::Util::indexes { $_ eq $value } @$r_array; return $cnt ? 1 : 0; }

This latter has the advantage that it's easily modifiable to return a list of indexes that match (since that's what indexes does already)

Using map to cast an array to a hash and testing keys is only useful if you'll be checking for the existence of several values in an array that won't change between your tests. So, I think the real question should be what value does this wrapper provide over using Perl's built-in capabilities?

I think the OP addressed that just fine -- it's syntactic sugar for those more familiar with OO-based languages who are trying to learn Perl, or who want to consistently use OO for everything for some reason.

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re^2: RFC: Idiomless Perl by radiantmatrix
in thread RFC: Idiomless Perl by bennymack

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.