On 07/02/2012 01:39, sono...@fannullone.us wrote:
On Feb 6, 2012, at 1:42 PM, Steve Bertrand wrote:

This may be easier. It uses the hash elements directly as an
array, then uses grep to see if the zip code is within the specific
state. It returns true if the state owns that zip code, and false
if it doesn't.

if ( grep( /^$customers_zip$/, @{ $states{ $customers_state } } ) ) {
        $match = "yes";
}

        Thanks, Steve.  Elegantly simple!

It is odd to use a regex here when the intention is a simple string
comparison

  grep( $_ eq $customers_zip, @{ $states{ $customers_state } } )

in fact, if the objective is to reduce the code to something as brief as
possible then this will do the trick

my $match = (grep $_ eq $customers_zip, @{$states{$customers_state}}) ? 'yes' : 'no';

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to