Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Hash and count of data values

by LTjake (Prior)
on Aug 18, 2003 at 13:53 UTC ( #284570=note: print w/replies, xml ) Need Help??


in reply to Hash and count of data values

Along with what bm said, it looks like you're forgetting to chomp off any newline characters.

use strict; my %count; while( <DATA> ) { chomp; $count{ $_ }++; } print "$_\t$count{ $_ }\n" for keys %count; __DATA__ 123 56 123 56 234 45 123 56 678 93 678 93

With chomp:

678 93 2 234 45 1 123 56 3

w/o chomp:

678 93 1 678 93 1 123 56 3 234 45 1

--
"To err is human, but to really foul things up you need a computer." --Paul Ehrlich

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-12-07 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?