in reply to Re^2: "possible typo" warnings in modules
in thread "possible typo" warnings in modules

Well how do you account for the behaviour that there are no errors when the syntax is correct, but an error when the syntax is wrong ( like a missing colon or scalars define twice with my)? Then if the syntax is ok, it lets it run and evaluation errors appear at runtime?

UPDATE added example

For instance this will stop at compile time:

#!/usr/bin/perl use strict; use warnings; use lib '.'; use WarnMe; print "1\n"; print $WarnMe::val,"\n"; print "2\n";
package WarnMe; use strict; use warnings; # syntax error my $val = $Some:Nonexistent::Pkg::variable; 1;
outputs:
zentara@:zentara$ ./WarnMe Global symbol "$Some" requires explicit package name at WarnMe.pm line + 7. syntax error at WarnMe.pm line 7, near "$Some:" Compilation failed in require at ./WarnMe line 5. BEGIN failed--compilation aborted at ./WarnMe line 5.

Clearly the Perl compiler is checking syntax first. If you fix that syntax error, the script will compile and run with issuing a non-fatal runtime error:

Name "WarnMe::val" used only once: possible typo at ./WarnMe line 8. 1 Use of uninitialized value in print at ./WarnMe line 8. 2

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^4: "possible typo" warnings in modules
by diotalevi (Canon) on Feb 17, 2007 at 19:27 UTC

    Your first example throws all the proper errors. I don't know how to replicate your environment to get that to stop throwing warnings. Your second example also throws the proper warnings.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      I agree they are both throwing proper warnings, but it's clear there is a difference in "compilation phase warnings" and "runtime warnings". The first example stops the compilation dead in it's tracks because of a syntax error. Wheras the programming error is allowed to pass as long as the syntax is correct.

      I think we are arguing over whether the Perl interpreter does a one pass or two pass scan of the code. I guess it only "appears" to do a syntax scan before it cancels the compilation, but I defer to your greater wisdom that it is actually a one pass operation. It seems to the end user that Perl is checking syntax first, and I see your point that it is a misunderstanding on my part, and the syntax scan is only an illusion.


      I'm not really a human, but I play one on earth. Cogito ergo sum a bum

        Well sure, there's a "second pass." When the code is actually run. Want to get a glimpse of what this stuff looks like when its finished being compiled? Use some of the B:: tools: perl -MO=Concise your-program.pl, perl -MO=Debug your-program.pl<c>, <c>perl -MO=Terse your-program.pl.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊