Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: count of a word occurrence

by jZed (Prior)
on Mar 23, 2004 at 04:17 UTC ( #338887=note: print w/replies, xml ) Need Help??


in reply to count of a word occurrence

my %hash; for (<DATA>) { s/^(\S+).*/$1/; $hash{$_}++ } use Data::Dumper; print Dumper \%hash; __DATA__ 817 5:00 817 5:00 817 5:15 123 4:45 817 5:30 495 7:45

Replies are listed 'Best First'.
Re: Re: count of a word occurrence
by DamnDirtyApe (Curate) on Mar 23, 2004 at 04:51 UTC

    Same thing, just slightly shorter (and maybe clearer):

    #! /usr/bin/perl use strict; use Data::Dumper; my %hash; /^(\d+).*/ and $hash{$1}++ for <DATA>; print Dumper \%hash; __DATA__ 817 5:00 817 5:00 817 5:15 123 4:45 817 5:30 495 7:45

    _______________
    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
      Death to dot-star! (It's useless in your example, and in jZed's.)

      The PerlMonk tr/// Advocate

        Good point, ++. My regexp started out as a s///, and I guess I missed pulling that out.


        _______________
        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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2021-11-29 14:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?