First: I second Utilitarian's (implied) advice re hashes.

Second: The shebang line is unnecessary under windows unless you have trailing modifies ( like  -T or  -w ) and definitely doesn't need escaped backslashes.

Third: these are a couple ways to do PART of what your code tries to do -- count the words.

#!/usr/bin/perl use 5.016; use strict; use warnings; #1018535 =head NO ARRAY METHOD (everything between here and the =cut line is +commented out) my $count; while ( <DATA> ) { for ( $_ =~ /\w+/g ) { $count++; } } print "COUNT: $count\n"; =cut END of (POD-syntax code which is tantamount to a) multi-line + comment # you could stuff the individual (not necessarily unique) words into a +n array, this way: # ie, this uses an ARRAY. Run the code to see what's happened here. my $i = 0; my ( $count, @count); while ( <DATA> ) { for ( $_ =~ /(\w+)/g ) { push @count, "$_ $i"; $i ++; } } for $count(@count) { say "Array element is: $count"; } __DATA__ This these that the and how who writ this code how now brown cow the fox jumped into the hencoop the lazy brown dog was azleep.

Note that the highest numeric value from the array method is 25, even though there are 26 words in the __DATA__ section. Look at the first value of the output and you'll find a zero... which is the way array elements are denominated -- the first element is $array[0].

If you wish to see the NON-ARRAY method used, move the =head and =cut down to surround the second (and currently operative) code. The data section must, of course, stay outside this hackish method of doing a multi-line comment in a script.

BUT, to identify and count unique words using the commonly recommended approach, use a hash.

And finally, if by any chance you mean you're seeing things like HASH(0x213F7) when you mention "numeric values," (though I don't see why) what you're seeing is effectively a pointer to the memory where the actual values are stored; to understand that (and how to get the actual values) you'll need to study referencing and dereferencing, in our estimable Tutorials section.


If you didn't program your executable by toggling in binary, it wasn't really programming!


In reply to Re: compute the occurrence of words ("under stand arrays") by ww
in thread compute the occurrence of words by BigGer

Title:
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, details, 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, summary, 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.