And why do you want to do that??

Um, because I can?

I am in the habit of testing everything, by which I mean "try to break it". Even small demo scripts for PerlMonks. It's just a habit of mine. Just as I never ever start a script without use strict;. My eyes are too old, my brain is too scattered (running ahead to the next thing while my fingers are still typing) ... too many times I've typed $thing{thang} when I meant $thing->{thang}, and so on and so on.

So, while I was "fooling" with the version of the script I made for the OP, and yours, I was throwing random values at it, to see what it would do. I threw some large numbers to see how line wrapping would affect it, and then I threw π at it. Of course I knew that such a value would break it: Array indices are supposed to must be integer values, as you point out above, and the matrix would break even if you could somehow pass in a non-integer.

What I found interesting, and what I drew to your attention since I thought you might also find it interesting, is that the two versions of the script output different values. Neither died nor threw an exception. Since the two versions of the code were almost identical, I found that odd.

I suspected the for loop, and roboticus very helpfully tracked down in the documentation and explained completely how Perl differs in handling

my $n = 3.14159; for (my $i=0; $i<$n; $i++)

and

my $n = 3.14159; for (0..$n)

Perhaps you already knew all about this, but I didn't, and I found it interesting, so I shared it.

Now you know why.

Remember: Ne dederis in spiritu molere illegitimi!

In reply to Re^4: Multidimentioal array by 1nickt
in thread Multidimentioal array by Subhrangshu Das

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.