[plug] Re: Perl Question: Searching an array
David Buddrige
buddrige at wasp.net.au
Wed Feb 26 16:55:35 WST 2003
thanks heaps! 8-)
David.
Brad Hill writes:
> convert the array to a hash and then it's trivial:
>
> #!/usr/bin/perl
>
> @myarray = ( "fish", "chicken", "beef" );
> %myhash = @myarray;
> print "found fash" if $myhash{"fash"};
> print "found fish" if $myhash{"fash"};
>
> ----- Original Message -----
> From: "David Buddrige" <buddrige at wasp.net.au>
> To: <plug at plug.linux.org.au>
> Sent: Wednesday, February 26, 2003 4:39 PM
> Subject: [plug] Perl Question: Searching an array
>
>
>> Hi all,
>>
>> I have a perl program that contains a very large array. I want to search
>> this array to determine if it contains a particular value. Is there a
>> faster way to search the array than this?
>>
>>
>> $search_val = "text-to-look-for";
>> $found = "false";
>> foreach $line ( @myarray )
>> {
>> if ( $search_val == $line )
>> {
>> $found = "true";
>> }
>> }
>>
>> I've beeen reading through "Learning Perl" but can't find any answer on
> this
>> one. 8-)
>>
>>
>> thanks heaps guys
>>
>> David Buddrige
>
More information about the plug
mailing list