Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I realise I am stupid and shouldn't have been let loose on PERL in a million years but I need help!! Can anyone PLEASE help me with a hash sorting problem I am having?? I will be eternally grateful!!!!!!! I have successfully created a hash containing all the keys and values I want but wish to merely sort the keys into ascending numerical order. Am I doing something wrong with my hash assignment? I cannot quite see why it won't work See excerpt below
foreach $sentence(@sentences) { <BR> $total_sentence +=1; <BR> @words = split(/[^\w'a-zA-Z0-9_'-?]+/,$sentence); <BR> $Counter =0; <BR> foreach $word(@words){ <BR> $Counter+=1; <BR> } <BR> $sentence_count{($Counter)}=$sentence_count{($Counter)}+1;<BR> + } <BR> sort {$a<=>$b} (keys (%sentence_count)); <BR> print ("\nThere are a total of $total_sentence sentences in this text\ +n"); <BR> while (($sentence_count,$word_count) = each(%sentence_count)) { <BR> print ("\nThere are $sentence_count sentences of $word_count words +\n"); <BR> } <BR>

In reply to Hash sort again!! by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (5)
    As of 2020-12-02 03:16 GMT
    Find Nodes?
      Voting Booth?
      How often do you use taint mode?

      Results (28 votes). Check out past polls.