Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Need help with Hash Values

Expand Messages
  • Sakura Kinomoto
    Thanks,It solved~~ ________________________________ From: Shlomi Fish To: perl-beginner@yahoogroups.com Sent: Thu, July 1, 2010 7:29:26
    Message 1 of 4 , Jul 2, 2010
    • 0 Attachment
      Thanks,It solved~~



      ________________________________
      From: Shlomi Fish <shlomif@...>
      To: perl-beginner@yahoogroups.com
      Sent: Thu, July 1, 2010 7:29:26 PM
      Subject: Re: [PBML] Need help with Hash Values

      On Thursday 01 Jul 2010 14:14:07 sxsakura wrote:
      > Em....While doing the homework that gives from the "Learning Perl" books.
      > The homework is "Give out some strings (a word per line) and count the word
      > that has been given" so I typed:
      > #! /usr/bin/perl -w
      >
      > while(<>)
      > {
      > <STDIN>;

      You don't need this statement (the "<STDIN>;" one). It just skips a line.
      Without it, it should be fine.

      Regards,

      Shlomi Fish

      > chomp;
      > $words{$_} += 1;
      > }
      >
      > foreach (sort keys %words)
      > {
      > print "$_ has appeared $words{$_} times\n";
      > }
      >
      > and run it,and these are what i typed and what it gave back:
      > hello
      > hello
      > hi
      > hi
      > nihao
      > nihao
      > hey
      > hei
      > hello has appeared 1 times
      > hey has appeared 1 times
      > hi has appeared 1 times
      > nihao has appeared 1 times
      >
      > Obviously,the words"hello","hi","nihao" has appeared 2 times,but the
      > program only counted 1 time,why? And if I use a array of values to read
      > the input data and then count it,it will goes well like:
      > @word=<STDIN>;
      > foreach (@word)
      > {
      > $counts{$_} += 1;
      > }
      > why~?
      > need help,thanks

      --
      -----------------------------------------------------------------
      Shlomi Fish http://www.shlomifish.org/
      Funny Anti-Terrorism Story - http://shlom.in/enemy

      God considered inflicting XSLT as the tenth plague of Egypt, but then
      decided against it because he thought it would be too evil.

      Please reply to list if it's a mailing list post - http://shlom.in/reply .


      ------------------------------------

      Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links






      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.