Good afternoon folks,

I started programming with perl last week and perl is my first language so I'm a bit of a newbie. Basically I need help with a multidimensional array.

I have a 100k by 3 multidimensional array, contained in a CSV file. Each constituent array is a point in a 2D space with an intensity value taking up the third entry. But I need perl to calculate the norms of each constituent array and add those as a fourth column to this multidimensional array. So I would have a 100k by 4 multidimensional array.

Here's my code:
sub norm{ $p=$#data; #I call the 100k x 3 array @data for($i=0;$i<=$p; $i++){ # iterates down @data $norm=(($data[$i][0])**2+($data[$i][1])**2)**(1/2); #calculate +s the norm push(@data[i],$norm); #pushes the norm into the correct row of + @data, yet I get an error. } }

Specifically my syntax checker tells me that the "Type of arg 1 to push must be array (not array slice) near "$norm)"

Aid me wise monks!


In reply to pushing multidimensional arrays by afalsename

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.