If you test a particular array for the existance of many values, it might be faster/easier to understand to use the Schwartzian Transform. For example:

my $matches = 0; foreach my $item (@items) { $matches++ if grep( $item eq $_, @list ); } print "All match!" if $matches == @items;

becomes:

my %st = map { $_ => undef } @list; my $matches = 0; foreach my $item (@items) { $matches++ if exists $st{$item}; } print "All match!" if $matches == @items;

The larger @items gets (relative to @list), the better the latter performs relative to the former. I don't know where the 0-point lies -- that is, I don't know at what point it becomes faster to use the latter form -- so use of Benchmark and Devel::DProf (and friends) would be essential.

It would be interesting (though decidedly niche) to see a module where the %st hash would be automatically maintained every time a particular array was updated. I'd probably use overload to create an interface like:

use List::AutoST; my $list = List::AutoST->new(); # these appear to behave like normal push @list, $some, $values, $here; $list[1] = $value2; # but then... print "Ok!" if $list->has('this value'); # or (also via overload) print "Ok!" if exists $list{'this value'};

I don't know about performance differences for that, but it would make an interesting and eas(y|ier) approach.

<radiant.matrix>
A collection of thoughts and links from the minds of geeks
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: RFC: Text::Grap by radiantmatrix
in thread RFC: Text::Grap by kwaping

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.