Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: hard referencing in hashes?!?

by DamnDirtyApe (Curate)
on Nov 08, 2002 at 02:28 UTC ( [id://211313]=note: print w/replies, xml ) Need Help??


in reply to hard referencing in hashes?!?

How about something like this:

#! /usr/bin/perl use strict ; use warnings ; use Data::Dumper ; my @match_arr = qw( count pick words ) ; my %match_hash = map { $_ => 1 } @match_arr ; my %word_count ; while ( <DATA> ) { my @words = split ; for ( @words ) { $word_count{$_}++ if $match_hash{$_} } } print Dumper \%word_count ; exit ; __DATA__ This is my data. I will first count all the words herein, then pick and choose the data I want. I can pick the words using grep.

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Replies are listed 'Best First'.
Re: Re: hard referencing in hashes?!?
by imlou (Sexton) on Nov 08, 2002 at 02:56 UTC
    Thanks! but for my assignment i only have to count all the words in a file. Thats why I used hashes....but i found the powerful use of EXISTS :P. Make life so much easier. Now my problem is sorting the results of each word by acending or decending order.

      Look at using a Schwartzian Transform:

      my @sorted = sort { $b->[1] <=> $a->[1] } map { [ $_, $word_count{$_} ] } keys %word_count ;

      _______________
      DamnDirtyApe
      Those who know that they are profound strive for clarity. Those who
      would like to seem profound to the crowd strive for obscurity.
                  --Friedrich Nietzsche
      generally we use sort

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://211313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-19 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found