after coding I realized that you didn't ask to keep the last match position - attribute last_pos - as state information. Right?

In that case this double data structure to grant you fast indexed access to sequences is overkill, and you should rather go with grandfathers design.

use strict; use warnings; use Data::Dump qw/pp dd/; use 5.10.0; # ========= Tests my $set = Some::Module->new(qw(foo bar bat)); say $set->contains('fox'); # false say $set->contains('foo'); # true say $set->contains('FOO'); # true say $set->after('foo'); # 'bar' say $set->is_last('bar'); # false say $set->is_last('bat'); # true package Some::Module; use Data::Dump qw/pp dd/; sub new { my ( $class, @sequence ) = @_; my $pos = 0; my %positions = map { lc($_) => $pos++ } @sequence; my $count = @sequence; my $obj = { sequence => \@sequence, positions => \%positions, count => $count, last_pos => undef, }; bless $obj, $class; } sub contains { my ( $self, $key ) = @_; my $pos = $self->{positions}{lc($key)}; $self->{last_pos} = $pos; return defined $pos; } sub after { my ($self, $key) = @_; my $pos = $self->{positions}{lc($key)}; return $self->{sequence}[$pos+1]; } sub is_last { my ($self, $key) = @_; my $pos = $self->{positions}{lc($key)}; return $pos == $self->{count} -1; }

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^2: Module for sets of strings, ordered, case-insensitive? by LanX
in thread Module for sets of strings, ordered, case-insensitive? by cxw

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.