I will admit from the start ... interested to find the filename printed instead of the expected "0".

Dang, dat don soun like no good english :D (I actually don't know, just sounds, well, interesting to me :)

FWIW, its all good, at least you're trying , to learn (as opposed just finish some program) :)

a) What is the actual purpose of the special scalar variable, $0, which holds the filename of the script (I have read perlvar, but still don't understand the significance);

That is the purpose, the hold the name of the script (hey, people want to know what it is, if they can )

b) Did I not get a warning about the undeclared variable because it was being assigned to a declared variable, or did I not get it because it was a special variable such as $_ and why should this be the case; and,

What undeclared variable, $0? Perl declares/defines/initializes $0 for you, its a pre-defined global variable

c) Did the count iterate to 1..9 because the special scalar variable, $0, was treated as zero due to the numeric lt (<) operator? Or, in other words, how was the condition able to be evaluated if it did not conform to initial expectations by being non-numeric?

This is equivalent to that for loop

#!/usr/bin/perl -- use strict; use warnings; { my $count = $0; LOOOOOP: while(1){ print "$count\n"; if( not ( $count < 10 ) ){ last LOOOOOP ; } else { $count++; } } undef $count; } __END__ $ perl junk junk Argument "junk" isn't numeric in numeric lt (<) at junk line 7. 1 2 3 4 5 6 7 8 9 10

Do you get it now?

Try another

#!/usr/bin/perl -- use strict; use warnings; { my $count = $0; LOOOOOP: { print "$count\n"; if( not ( $count < 10 ) ){ goto NO_MORE_LOOP; } else { $count++; goto LOOOOOP; } } NO_MORE_LOOP: undef $count; }

I apologise in advance for the "baby Perl" questions.

This free book covers this level of experience :) http://learn.perl.org/books/beginning-perl/


In reply to Re: Curious about a quirk with the special variable, $0 by Anonymous Monk
in thread Curious about a quirk with the special variable, $0 by mrdurtal

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.