[ale] OT: one for the Perl Guru's

Jerry Yu z.yu at voicecom.com
Wed May 7 09:22:23 EDT 2003


directly from perlfunc man page (switch a and b to gets ascending order)
-------------------------------------------------------
      To sort a hash by value, you'll need to use a
       "sort" function.  Here's a descending numeric sort
       of a hash by its values:

   foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash)

On Wed, 7 May 2003, Robert L. Harris wrote:

#
#
#Got a different one for ya, I know I've done it, just can't find my
#archived script and it's just bugging me.
#
#I've loaded %PBFoos with a list of words and the number of times they
#are seen so the output of:
#
#foreach $Loop1 (keys(%PBFoos)) {
#  print "The Word: $Loop1   Appeared: $PBFoos{$Loop1}\n";
#}
#
#This is doing what I want but the problem is I need it to sort by
#$PBFoos{$Loop1} not $Loop1 such that it's sorted with the entry found
#the most number of times first to the least last.
#
#Thanks,
#  Robert
#
#P.S.: The below was a perfect answer.  Thanks alot for that.
#
#
#
#Thus spake Fletch (fletch at phydeaux.org):
#
#> >>>>> "Robert" == Robert L Harris <Robert.L.Harris at rdlg.net> writes:
#> 
#>     Robert> Problem with this grep is that I have a sentance such as
#> 
#>     Robert> <Header crap> File Foo changed size while backups wile
#>     Robert> running on host Bar
#> 
#>     Robert> There's a couple other variations but I'd like it to next
#>     Robert> if they're there also.  The keys are pretty much 3-4 word
#>     Robert> phrases.
#> 
#> Aaah, I misread the problem.  You still can use grep, you just use it
#> a little differentently.  You can give grep an arbitrary EXPR (or
#> BLOCK) to evaluate, it doesn't have to be just a m//.
#> 
#> 
#> my @ignore = ( qr/changed size/,
#>                qr/file removed/,
#>                qr/warp core breach imminent/,
#>               );
#>                 
#> while( my $line = <> ) {
#>   next if grep $line =~ $_, @ignore;  
#> 
#>   ## go on and process interesting $line
#> }
#> 
#> 
#> -- 
#> Fletch                | "If you find my answers frightening,       __`'/|
#> fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
#> 770 294-0820 (m)      |  scary questions." -- Jules                =(___)=
#>                       |                                               U
#> _______________________________________________
#> Ale mailing list
#> Ale at ale.org
#> http://www.ale.org/mailman/listinfo/ale
#
#:wq!
#---------------------------------------------------------------------------
#Robert L. Harris                     | PGP Key ID: E344DA3B
#                                         @ x-hkp://pgp.mit.edu 
#DISCLAIMER:
#      These are MY OPINIONS ALONE.  I speak for no-one else.
#
#Diagnosis: witzelsucht  	
#
#IPv6 = robert at ipv6.rdlg.net	http://ipv6.rdlg.net
#IPv4 = robert at mail.rdlg.net	http://www.rdlg.net
#

Jerry Yu				+1-404-487-8544 (O)
systems engineer			jerry.yu at voicecom.com
is support, voicecom, llc		www.voicecom.com

_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list