I thought I had understood your comment, but there is still something I can't figure out. Why does:
my @test=qw(1 2 3 4 5 6); (@test % 2) ? print "uneven\n" : print "even\n"; print "end\n";

Work fine, while the two versions below result in "uneven" in the first case and "even" in the second, when both should be reported as "even".

@test=qw(1 2 3 4 5 6); testthearray1(\@test); sub testthearray1{ (@_ % 2) ? print "uneven\n" : print "even\n"; } testthearray2(); sub testthearray2{ (@_ % 2) ? print "uneven\n" : print "even\n"; }

The BlueCamel says "Any arguments passed to a Perl routine come in as the array @_" (pg 219), and this is clearly what you assume happens when you assign my @mat = @_ in the second line. When I include something like  print "@_" to the second line in the  sub testhearray (1 and 2), it shows up as an undefined array (or rather, ARRAY(0x9b25fd8) in the first, and nothing in the second).

I also find it strange that it is the first of the two subs that apparently requires a reference to @test instead of @_, when this is the one which includes a reference to the array when calling the subroutine.

What am I overlooking? (this humbled novice asks).


In reply to Re: Re: Nearest Neighbour Analysis subroutine by Elias
in thread Nearest Neighbour Analysis subroutine by Elias

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.