cybersmithuk has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have written a script by using hashes. In my script I have used values independently. At the end, I have got output of a list of hash values...but now what I am looking for is getting the keys for the values (output). In simple, I am looking for the corrosponding keys for the values (output). The following is my script. Thank you very much.
#!/usr/local/bin/perl use warnings; # open a file and assign the filehandle FILE open(FILE, "2.txt") or die("can't open myfile.txt: $!\n"); while(<FILE>) { if($_ =~ /\s+(\S+)\s+(\S+)/) { $hash{$1} = $2; push(@index,$1); push (@a2, $2); } } close(FILE); # close the filehandle $i=0; while ($i<= ($#a2 - 1)) { $c1=$a2[$i]; $c2=$a2[$i+1]; $c3=$a2[$i+2]; $c4=$a2[$i+3]; $c5=$a2[$i+4]; $c6=$a2[$i+5]; $c7=$a2[$i+6]; $c8=$a2[$i+7]; $c9=$a2[$i+8]; $i++; if (($c1<$c2) && ($c2<$c3) && ($c3<$c4) && ($c4<$c5) && ($c5>$c6) && ( +$c6>$c7) && ($c7>$c8) && ($c8>$c9)) { $peak=$c5; print $peak, "\n"; } }
20050426 Janitored by Corion: Added formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing keys through values
by holli (Abbot) on Apr 26, 2005 at 10:33 UTC | |
by cybersmithuk (Initiate) on Apr 26, 2005 at 10:52 UTC | |
|
Re: Accessing keys through values
by salva (Canon) on Apr 26, 2005 at 10:35 UTC | |
|
Re: Accessing keys through values
by Roy Johnson (Monsignor) on Apr 26, 2005 at 11:59 UTC | |
by cybersmithuk (Initiate) on Apr 26, 2005 at 12:08 UTC | |
by cybersmithuk (Initiate) on Apr 26, 2005 at 13:31 UTC | |
|
Re: Accessing keys through values
by inman (Curate) on Apr 26, 2005 at 13:33 UTC | |
|
Re: Accessing keys through values
by TomDLux (Vicar) on Apr 26, 2005 at 20:28 UTC |