in reply to Matching First Character of Strings Efficiently

How about a simple grep:
my $str_a = 'Foo'; # Can be any length for my $str_b (grep /^$str_a/, @list ) { # Can + be any number of items expensive_function($str_a , $str_b); }
Will call expensive_function only on items that start with 'Foo' (Which can be limited to one character if thats what you Really want)

Update: This is the same as delirium's solution, above.

Offense, like beauty, is in the eye of the beholder, and a fantasy.
By guaranteeing freedom of expression, the First Amendment also guarntees offense.

Replies are listed 'Best First'.
Re: Re: Matching First Character of Strings Efficiently
by Limbic~Region (Chancellor) on Mar 15, 2004 at 20:10 UTC
    NetWallah,
    Actually it is not the same. You are checking to see if string b starts with the entire string a. This would not meet the criteria of only checking first letters. Besides, changing the looping construct was not permitted.

    Cheers - L~R