G'day gelbukh,

Welcome to the Monastery.

"Sorry for a stupid question! But I want to learn: ..."

A '#' introduces a comment. See "perlsyn: Comments". So, when compiling, Perl sees your lines 9 to 12 as:

my $N= say "N = $N";

As Perl doesn't care about the intervening whitespace, that's basically:

my $N= say "N = $N";

Assignment is a right-to-left operation. See "perlop - Perl operators and precedence". That's a fairly long page; the parts most pertinent to your question are:

So, Perl attempts to compile 'say "N = $N"' first. It hasn't evaluated the left side of the assignment ('my $N') yet, so it sees $N as a "Global symbol" and hence the error message.

There is a subtle point here that isn't immediately, or intuitively, obvious. A statement such as 'my $x = ...;' has two distinct parts:

I see a couple of posts showing how to get length and last index of an array. Another way to get the length is:

my $N= 0+@Org;

As a further tangential point, a "use VERSION" statement, where VERSION is 5.12 or greater, you get 'use strict;' automatically. I like to put the use VERSION statement first: if the user does not have a sufficiently high enough version, you might as well stop here rather than doing other (effectively) pointless processing. Accordingly, instead of

use strict; use warnings; use 5.020;

I'd write

use 5.020; use warnings;

Just something to consider for future reference.

— Ken


In reply to Re: Strange compile error? by kcott
in thread Strange compile error? by gelbukh

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.