Thanks, I found a simpler approach though. I set a variable to '1' and check it in an if statement: if ($check == 1) { Perform steps }else{ Perform other steps. }
After I pass the hashes I need to use for "Perform steps" I set the variable to '0' and then pass the next set of hashes. Since the value is no longer '1', the "Perform other steps" is processed. Fortunately, I only have two sets of hashes so this won't get difficult to maintain. Keep up with me and what I'm up to: http://theillien.blogspot.com [EMAIL PROTECTED] wrote: > Hi again, > > In that case can use the following: > if ($dept and exists($dept->{customer}{user}){ ....}else{....} > > Yaron Kahanovitch > ----- Original Message ----- > From: "Mathew Snyder" <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Cc: "Perl Beginners" <beginners@perl.org> > Sent: Sunday, May 13, 2007 10:22:53 AM (GMT+0200) Auto-Detected > Subject: Re: Stuck on a hash referrence, kinda > > That's the problem. 'user' isn't in the first hash. It's in the second hash. > The hash looks like $dept{customer}{user}. I need to skip $dept{customer} and > check for $dept{customer}{user}. > > Mathew > Keep up with me and what I'm up to: http://theillien.blogspot.com > > > [EMAIL PROTECTED] wrote: >> Hi, >> >> I am not sure that I understand your problem. >> In General if you want to check the existence of the key "user" in the first >> hash, you can use the following >> if ($dept and exists($dept->{user}){ ....}else{....} >> >> >> Hope that helps >> >> >> Yaron Kahanovitch >> ----- Original Message ----- >> From: "Mathew Snyder" <[EMAIL PROTECTED]> >> To: "Perl Beginners" <beginners@perl.org> >> Sent: Sunday, May 13, 2007 9:54:38 AM (GMT+0200) Auto-Detected >> Subject: Stuck on a hash referrence, kinda >> >> A subroutine I'm working on takes two hash references. The hashes are each >> actually a HoH. >> >> timesheet(\%opsTotal, \%opsEnvTotal); >> >> The problem I'm having is that I need to look past the first hash and into >> the >> second for the existence of a particular key. I'm not sure how to go about >> doing this. >> >> sub timesheet { >> my ($dept, $env) = @_; >> >> #This is where I need help. 'user' is in the second hash but I'm not sure >> how >> #to get past the first one. Should I use a foreach and step through each >> key? >> if (exists $dept->{user}) { >> open TIMESHEET, >> ">/work_reports/user/ops_timesheet_weekof_$endDate.txt"; >> }else{ >> open TIMESHEET, >> ">/work_reports/user/eng_timesheet_weekof_$endDate.txt"; >> } >> >> print TIMESHEET "Timesheet for $startDate to $endDate\n\n\n"; >> >> foreach my $environ (sort keys %$dept) { >> #Print the header for our data >> print TIMESHEET "$environ", "\n"; >> printf TIMESHEET "%10s%8s\n", "User", "hh:mm"; >> print TIMESHEET ("-" x 30); >> print TIMESHEET "\n"; >> foreach my $name (sort keys %{ $dept->{$environ} }) { >> printf TIMESHEET "%10s%8s\n", "$name", >> "$dept->{$environ}->{$name}"; >> } >> printf TIMESHEET ("-" x 30); >> print TIMESHEET "\n"; >> printf TIMESHEET "%18s\n\n", "$env->{$environ}"; >> } >> close TIMESHEET; >> } > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/