Hi there I'm attempting to write a perl script that opens a directory from the command line, opens each file at a time and then according to the information extracted from each line in the text file, stores how many times a set of numbers within a particular 'range' occurs in the text.
So, for example, if I want to count how many times x occurs with a value between 180-175 occurs when y = any value between 170-165, I want to store this information in a array identifying this value range and then print off the total number of times the desired x,y range occurs at the end. Here is a snippet of my code thus far:
$underscore = "_"; for($i = -180; $i < 181; $i = $i+5) { $j = $i+5; if(($x >= -180) && ($x < -175) && ($y >= $i) && ($y < $i+5 )) { $k++; $x1 = "substr($i, 1, 3)"; $x2 = "substr($i, 1, 3)"; $y1 = substr($i, 1, 3); $y2= substr($j, 1, 3); # attempting to name array according to value range $array = "array$underscore$x1$underscore$x2$underscore$y1$unde +rscore$y2"; $count = $count +1; $array[$k] = ($count); print "$array[$k]";
This doesnt seem to work at all as I am unable to get the array value to print out. Eleswhere, the array wont print out when I use print @array either. I can only assume I'm not naming it correctly or something. Any help would be much appreciated

In reply to headache with arrays. by Anonymous Monk

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.