develooper Front page | perl.beginners | Postings from March 2002

RE: If statement

Thread Previous | Thread Next
From:
Zeus Odin
Date:
March 31, 2002 05:13
Subject:
RE: If statement
Message ID:
NCBBJGKHAPMBPELHFAHMIELODMAA.zeus.odin@verizon.net
#!D:\perl\bin\perl -w
use strict;

my %data;

# fill in 11 other states
my @state = qw(MA CI DE IN OH);    

# Make each element of @state a key of hash %data
# Set each value equal to 1 (true)
# Refer to Perl Cookbook
# Recipe 4.7: Finding Elements in One Array but Not Another
$data{ @state } = (1) x @state;

# Start loop here that reads each Access record 
   # Check if the present state is one of the 16 
   # $statefield is the state field of the ODBC
   # record object: $rs->Fields('state')->value
   # Refer to ActivePerl Help: Using OLE with Perl
   If ( $data{$statefield} ) {
   # OR If ( $data{uc($rs->Fields('state')->value)} ) {
      # Process data
   }

# End loop here that reads each Access record

-----Original Message-----
From: Ned Cunningham [mailto:Ned.Cunningham@MONRO.COM]
Sent: Friday, March 29, 2002 11:46 AM
To: beginners@perl.org
Subject: If statement


HI,
I am having a very newbie problem.
I am reading an Access database with ODBC and have my data read into

$Data{STATE}

My problem is now I need to match to 16 different states.



I have so far

If ( $Data{STATE} eq "MA" )

Process data


My question is should I use an array to test against and how to code it?

??-
@state="MA CI DE IN OH";

Thank you for anyhelp



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About