I'd probably use a tied array.

#!perl use strict; use warnings; use feature 'say'; use Data::Dumper; BEGIN { package Array::CaseFolded; # Perl 5.16 has 'fc' feature; older Perls can just use 'lc'. use if $] >= 5.016, feature => 'fc'; BEGIN { $] < 5.016 and eval 'sub fc ($) { lc $_[0] }' }; # Copied from Tie::StdArray. # Altered STORE, PUSH, UNSHIFT, and SPLICE. sub TIEARRAY { bless [], $_[0] } sub DESTROY { } sub EXTEND { } sub FETCHSIZE { scalar @{$_[0]} } sub STORESIZE { $#{$_[0]} = $_[1]-1 } sub STORE { $_[0]->[$_[1]] = fc $_[2] } sub FETCH { $_[0]->[$_[1]] } sub CLEAR { @{$_[0]} = () } sub POP { pop( @{$_[0]} ) } sub PUSH { my $o = shift; push( @$o, map fc $_, @_ ) } sub SHIFT { shift( @{$_[0]} ) } sub UNSHIFT { my $o = shift; unshift( @$o, map fc $_, @_ ) } sub EXISTS { exists $_[0]->[$_[1]] } sub DELETE { delete $_[0]->[$_[1]] } sub SPLICE { my $ob = shift; my $sz = $ob->FETCHSIZE; my $off = @_ ? shift : 0; $off += $sz if $off < 0; my $len = @_ ? shift : $sz-$off; return splice( @$ob, $off, $len, map fc($_), @_ ); } # Utility functions sub contains { my ( $arr, $value ) = ( shift, fc shift ); !!grep $value eq $_, @$arr; } sub after { my ( $arr, $value ) = ( shift, fc shift ); my $found = -1; for my $i ( 0 .. $#$arr ) { next unless $arr->[$i] eq $value; $found = $i; last; } $found >= 0 and $found < $#$arr and return $arr->[ $found + 1 +]; return undef; } }; tie my @arr, 'Array::CaseFolded'; @arr = qw( Foo BAR baz ); print Dumper(\@arr); say tied(@arr)->contains( 'Bar' ); say tied(@arr)->after( 'Bar' );

In reply to Re: Module for sets of strings, ordered, case-insensitive? by tobyink
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.