Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a hash key based on the value 7

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
US
Hello all,

I know I can get a hash value based on the key as in:

Code:
my $var = $hash{$key};

but haow can I get a key when I know the value?

Thanks,

Nick
 
Paul,

Thanks for the reply. I do not think that will work though. When I run the report in December 2005 the months for the 4 month chart:

12, 11, 10, 9

With your code the year would be decremented to 2004 for each month except for September.

Is that right?

Nick

 
I'm thinking that I will have to handle each "transition" month individually as in:

$rpt_month = Jan
Manually set $last4months[2] = 12
Manually set $last4months[1] = 11
Manually set $last4months[0] = 10
$rpt_month - Feb
Manually set $last4months[2] = 1
Manually set $last4months[1] = 12
Manually set $last4months[0] = 11

And so on unless you folks can conjur up a more efficient way?
 
Kevin,

Thanks for the reply but wouldn't that be the same result as:

if ($close_month eq $last4months[0])

Meaning that if there was NO transition in months (ie: Feb, Mar, Apr, May) I would still get the tickets for May 04 AND May 05?

Nick

Honestly, without being able to run the code I'm not sure. Running a test or two will tell.
 
Code:
my @last4months=($months[$curr-4],$months[$curr-3],$months[$curr-2],$months[$curr-1]);
[COLOR=red]if ($last4months[1] >= 10) {# if the first of the last 4 mths is greater than october
                            # we have a case for transition[/color]
  $ly = 0; #init var
  foreach (@last4months) {  # iterate over last 4 months
    if ($_ >= 10) {         # if its greater than oct, it was last year
      $last4years[$ly]=$year-1;
    } else {                # else its this year
      $last4years[$ly]=$year;
    }
    $ly++;                  #increase counter
  }  
} [COLOR=red] else {
  @last4years=($year, $year, $year, $year);
} [/color]
Nick your assumption was correct. I have a headcold, and wasn't paying attention. :(
the last 4 months array for a case of transition should look like one of the following in red
Code:
01,02,03,04
02,03,04,05,
03,04,05,06
04,05,06,07
05,06,07,08
06,07,08,09
09,10,11,12
[COLOR=red]10,11,12,01
11,12,01,02
12,01,02,03[/color]
so if the first month in the array is greater than or equal to ten, look to change those years, else each year is the same as the current

HTH
--Paul

cigless ...
 
Thanks Paul..I get it now. I'll try it out Monday and let you know.

You are an awesome programmer.

Nick
 
Code:
  if ($last4months[1] >= 10)
needs to be
Code:
  if ($last4months[0] >= 10)
unless you've been messing with using non-zero-based arrays.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top