in reply to Matching First Character of Strings Efficiently
Trade a little setup time for speed in the loop and use a hash?
my @list = ...; my %list; @list{ map{ substr $_, 0, 1 } @list } = (); my $str_a = 'Foo'; my $first_c = substr $str_a, 0, 1; for my $str_b ( @list ) { next if exists $list{ $first_char }; expensive_function($str_a , $str_b); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Matching First Character of Strings Efficiently
by Limbic~Region (Chancellor) on Mar 15, 2004 at 20:16 UTC | |
by BrowserUk (Patriarch) on Mar 15, 2004 at 21:53 UTC | |
by Limbic~Region (Chancellor) on Mar 15, 2004 at 22:35 UTC | |
by BrowserUk (Patriarch) on Mar 16, 2004 at 00:07 UTC |