Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sonam:</p> <p>I've reedited your post in order to help format it for reading. Study the <a href="https://stackoverflow.com/editing-help">Markdown Editing Help Guide</a> and that'll make your posts clearer and easier to understand. Here are a couple of hints:</p> <ul> <li>Indent your code by four spaces. That tells Markdown to leave it alone and don't reformat it.</li> <li>When you make a list, put astricks with a space in front. Markdown understands it's a bulleted list and formats it as such.</li> </ul> <p>Press "Edit" on your original post, and you can see what changes I made.</p> <hr> <p>Now on to your post. I'm not sure I understand your <em>data</em>. If your data was in a hash, the keys would be unique. You can't have duplicate keys in a hash, so where is your data coming from?</p> <p>For example, if you're reading it in from a file with two numbers on each line, you could do this:</p> <pre><code>use autodie; use strict; use warnings; open (my $data_fh, "&lt;", "$fileName"); my %hash; while (my $line = &lt;$data_fh&gt;) { chomp $line; my ($key, $value) = split /\s+/, $line; $hash{$key}++; } foreach my $key (sort keys %hash) { print "$key appears $hash{$key} times\n"; } </code></pre> <p>The first three lines are <a href="http://perldoc.perl.org/index-pragmas.html" rel="nofollow noreferrer">Perl pragmas</a>. They change the way Perl operates:</p> <ul> <li><code>use autodie</code>: This tells the program to die in certain circumstances such as when you try to open a file that doesn't exist. This way, I didn't have to check to see if the <code>open</code> statement worked or not.</li> <li><code>use strict</code>: This makes sure you have to declare your variables before using them which helps eliminate 90% of Perl bugs. You declare a variable <strong><em>most of the time</em></strong> using <code>my</code>. Variables declared with <code>my</code> last in the block where they were declared. That's why <code>my %hash</code> had to be declared before the while block. Otherwise, the variable would become undefined once that loops completes.</li> <li><code>use warnings</code>: This has Perl generate warnings in certain conditions. For example, you attempt to print out a variable that has no user set value.</li> </ul> <p>The first loop simply goes line by line through my data and counts the number of occurrences of your key. The second loop prints out the results.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload