karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/env perl use strict; use warnings; use feature qw(say); my $nose = qq(cuke); $nose !~/fubar/ and say "Super!" __END__

<Update: Thanks to all who helped.

Replies are listed 'Best First'.
Re: Why does this compile?
by choroba (Cardinal) on Nov 25, 2024 at 17:12 UTC
    Do you mean the absence of a semicolon before the __END__? Even this compiles and runs:
    $nose !~/fubar/ and say "Super!"__END__

    The __END__ token just tells Perl "stop reading the source right here". perlsyn says "Every simple statement must be terminated with a semicolon, unless it is the final statement in a block, in which case the semicolon is optional". This is exactly the optional case.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Doh! I am somewhat surprised. I didn't think of the idea with the block. I connect block with curly brackets. But Perl is jesuitically sophisticated. From ibidem:

      ” In Perl, a sequence of statements that defines a scope is called a block. Sometimes a block is delimited by the file containing it (in the case of a required file, or the program as a whole), and sometimes a block is delimited by the extent of a string(in the case of an eval). But generally, a block is delimited by curly brackets, also known as braces. We will call this syntactic construct a BLOCK. Because enclosing braces are also the syntax for hash reference constructor expressions (see perlref), you may occasionally need to disambiguate by placing a ; immediately after an opening brace so that Perl realises the brace is the start of a block. You will more frequently need to disambiguate the other way, by placing a + immediately before an opening brace to force it to be interpreted as a hash reference constructor expression. It is considered good style to use these disambiguating mechanisms liberally, not only when Perl would otherwise guess incorrectly.”

      In this case, the entire program - or main.

      Thanks and regards, Karl

Re: Why does this compile?
by jdporter (Paladin) on Nov 25, 2024 at 16:24 UTC

    uh... Because it's valid Perl? Why do you think it shouldn't?

Re: Why does this compile?
by talexb (Chancellor) on Nov 26, 2024 at 17:27 UTC

    Another way to think of this is that each statement in Perl is separated by a semi-colon. So, for example, if you have just one statement, you don't need a terminating semi-colon. That's why perl -e 'print "Hello world!\n"' (without a terminating semi-colon) is valid.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.