A few problems, and they're all in the "Perl will give you enough rope to hang yourself" category.... $x1 and $x2 are going to be set to the literal text "substr(20,1,3)" (for example... the 20 could be any number in the range of -180 and 180). Why would you want substr to appear as literal text?

$y1 is going to be set to the string value of the 2nd digit from the left of $i, extending for three digits to the right. That means when $i is negative, the minus sign is left off. When it's positive, the high-order digit is left off. The same problem applies to the $y2 assignment. *sigh*

$array = "array$underscore$x1......etc" looks to me like you're trying to create a symbolic reference. Don't bother, that is a road to madness. Use real references instead, or a hash whos keys are this concaucted name.

And if you did absolutely have to muck up your symbol table with symbolic references, the syntax would be ${$array}[$k] = $count;, though I'm telling you, that's not what you want to be doing in your early stages of Perl learning...and probably not even in the later stages either.

You can read up on Perl's references at perlref and perlreftut. String quoting interpolation is covered in perlop. And of course there's substr.


Dave


In reply to Re: headache with arrays. by davido
in thread 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.