Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

count frequency correspondint to one column

by genome (Novice)
on Jun 08, 2015 at 16:28 UTC ( [id://1129455]=perlquestion: print w/replies, xml ) Need Help??

genome has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on count frequency correspondint to one column

Replies are listed 'Best First'.
Re: count frequency correspondint to one column
by Your Mother (Archbishop) on Jun 08, 2015 at 16:38 UTC
Re: count frequency correspondint to one column
by stevieb (Canon) on Jun 08, 2015 at 16:39 UTC

    Cross-posted at StackOverflow. Please make it known in your posts when you're cross posting on numerous sites, and you should at least wait a reasonable amount of time for people to answer before asking somewhere else.

    A few other things... we appreciate it if you post what you've actually tried, and when you do post, put input data, code and error messages in <code></code> tags.

Re: count frequency correspondint to one column
by Hermano23 (Beadle) on Jun 08, 2015 at 16:38 UTC
    If there is a space between each row's entries, just use the split() function. For example, split(' ', 'a sk asd ') will give you an array {a, sk, asd}. From here you have a few options, but now it is easy look through one index at a time. Maybe make a hash of entries and their frequencies?
Re: count frequency correspondint to one column
by Hosen1989 (Scribe) on Jun 08, 2015 at 22:15 UTC

    Hi there,

    if you want to learn try think before ask ^_^ OK

    now you can try this code as it worked with me, I put sample data in test file $File_Name = 'data.txt'

    #!/usr/bin/perl -w use strict; use warnings; my $File_Name = 'data.txt'; my %Aggr; open(FH, "< ./$File_Name") or die "couldn\'t open [$File_Name]\n".$!; my @Data = <FH>; foreach my $line(@Data){ my @tmpRaw = split / /, $line; foreach my $Item(@tmpRaw){ chomp($Item); $Aggr{$Item}++; } } foreach my $key (sort keys %Aggr){ print $key.":".$Aggr{$key}."\n"; } close(FH);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-24 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found