Thanks for your help, this is what the final code
looks like.

sub load_keys_file
{
        open(KEY,$keys_file) || die "could not open $file:
$!\n";
        while (<KEY>)
        {
                next unless (/^\S/ && !/^#/);          # make sure
there's something to input and line does not start
with #
                ($old_phase,$new_phase,$ii_new_phase)=split /\t/;  
# split the line by tab
                chomp ($ii_new_phase);
                $phase_hash{$old_phase}=$new_phase;
                $ii_hash{$old_phase}=$ii_new_phase;
                #print
"$phase_hash{$old_phase}\t$ii_hash{$old_phase}\n";
        }
close KEY;

}
sub remap_phases
{
        if ( $phase_hash{$Phase})
        {
                $Phase = $phase_hash{$Phase};
        }
        elsif (($Phase eq "") || ($Phase eq " "))
        {
                $Phase = "NOT MAPPED";
        }
        else
        {
                print "Phase not found in keys file: $Phase\n";
        }
        
        
        if ( $ii_hash{$ii_phase})
        {
                $ii_phase = $ii_hash{$ii_phase};
        }
        elsif (($ii_phase eq "") || ($ii_phase eq " "))
        {
                $ii_phase = "NOT MAPPED";
        }
        else
        {
                print "II Phase not found in keys file:
$ii_phase\n";
        }
}


--- Bob Showalter <[EMAIL PROTECTED]>
wrote:
> > -----Original Message-----
> > From: James Ferree [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, August 08, 2001 4:42 PM
> > To: James Ferree; [EMAIL PROTECTED]
> > Subject: Re: Loading file into hash
> > 
> > 
> > 
> > --- James Ferree <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > > 
> > > I am looking for a way to load a file containing
> the
> > > following example data into a hash
> > > 
> > > #From   TO
> > > Jim     James
> > > Art     Arthur
> > > John    Arthur
> > > 
> > > Then when $a=Jim I would like to convert it to
> > > $a=James.
> > > 
> > > Can this be done?
> > > 
> > > Jim
> > > 
> > 
> > Thanks to your help so far, I have the following:
> > 
> > sub load_keys_file
> > {
> >     open(KEY,$keys_file) || die "could not open
> $file:
> > $!\n";
> >     while (<IN>)
> 
> This should be while(<KEY>), no? That's the
> filehandle you just
> opened?
> 
> >     {
> >             next unless (/\S/ && /^#/);          # make sure
> > there's something to input and line does not start
> > with #
> >             ($old_phase,$new_phase,$ii_new_phase)=split
> /\t/;  
> > # split the line by tab
> >             $phase_hash{$old_phase}=$new_phase;
> >             $ii_hash{$old_phase}=$ii_new_phase;
> >     }
> > close KEY;
> > 
> > 
> > Now, how do I check to see if a hash value is
> defined?
> > 
> > I thought this would work but I get a syntax error
> > 
> > if ( $phase_hash($Phase))
> 
> You need curlies: $phase_hash{$Phase}
> 
> Now, the test
> 
>    if ($phase_hash{$Phase})
> 
> is testing for the "truth" of the hash entry. It
> will be considered "false"
> if it evaluates to "", "0", or numeric 0. All other
> values are considered
> "true". Note that the undef value evaluates to ""
> when tested in this way.
> 
> There are actually three kinds of tests you can
> make:
> 
>    if ($phase_hash{$Phase}) { ... }         # tests
> for "truth"
>    if (defined $phase_hash{$Phase}) { ... } # tests
> for any value but undef
>    if (exists $phase_hash{$Phase}) { ... }  # tests
> whether key exists
> 
> Read
> 
>    perldoc -f defined
>    perldoc -f exists
> 
> for more details. 
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to