Hi,

Suppose I have this code:

#/usr/local/bin/perl
use warnings;
use strict;
use subs 'verify';

my %where=(
       Gary => "Dallas",
       Lucy => "Exeter",
       Ian =>  "Reading",
       Samantha => "Oregon"
   );

# Then i open a logfile

open FH, '<', $logfile or die "Can't open $logfile!: $!";

# Now, for every line in the logfile, I will retrive a particular string, let's 
say a person's name and verify if it exists in my hash above:

while (<FH>){
(my $person) = $_ =~ /person=(\S+)/;
my $personstatus = verify(\%where,$person);

# And do anything if the personstatus is this and that.


# Now,  on my sub "verify", I would like to know if the person exists in my 
hash.

sub verify {
my $where = shift @_;
my $person = shift @_;
my $personstatus;

if (exists $$where{$person}){

$personstatus =1;
}else {
   $personstatus = 0;
     }

$personstatus;
}

Am I thinking as this is how it should be done when passing hashes to a 
subroutine? My program doesn't work and I know it has something to do with the 
"my $personstatus" line as well as "if (exists $$where{$person} line.
Can you show me the right way of passing hashes to subroutines? Thanks.

I also tried declaring %where as 'our' so that I can use "if (exists 
%where{$person}" instead of "if(exists $$where{person}) but i still can't make 
it work.


Do you know if I am making any sense here?

Thanks








 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 

Reply via email to