Re: Searching a sorted array of strings



In article <1141163689.919307.289810@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"DJ Stunks" <DJStunks@xxxxxxxxx> wrote:

one man army wrote:

and I did look at that entry, actually, after both searches failed. And
that entry says "use a hash, here is how" or "use grep, which is slower."

So my example stands, it is what I said it is, searching a sorted
array of strings in Perl.

I don't understand...


I am not saying anyone should do anything, of course not! Its not that
complicated... I wanted to do something, here is the working code to do
that. Maybe someone will search and find it. Maybe no one cares.
Whatever. It seems like an array of strings and searching it _is_ a
reasonable thing to request in a programming language. Just because a
Hash is easy in Perl doesn't make it an array of strings. BUT MINUTIA, I
dont really care.

Since I am getting the hang of Perl today, things like string compare,
the number of elements in an array, using the er, subroutine
capabilities of Perl to get an arguement - thats all good. Beginner
land, remember? :-)

And actually, I am a really great coder. Just not in Perl. :-)

So you say really preprocess the array to make it a Hash, like

%CA_Cities = ( 'San Francisco' => 1, 'Los Angeles' => 2 );

or

@CA_Cities = ( "San Francisco", 1, 'Los Angeles', 2 );
%CA2 = @CA_Cities;

and that is the WAY. I can try that, too.
.



Relevant Pages