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