Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Non-traditional, Line by Line Compilation in Perl

by sumeetgrover (Monk)
on Dec 07, 2011 at 11:11 UTC ( [id://942215]=perlmeditation: print w/replies, xml ) Need Help??

This might have been previously found, but very interesting to know that the compilation carried out by Perl through the perl -c is non-traditional. In C, compilation would throw out all the syntax errors at once since the compiler would read through the entire code.

Interesting to discover that Perl compilation / parse tree building is line by line, therefore, on a 100 line program, if an error was encountered on line 10, the message thrown out by the compiler is:
failed--compilation aborted at MyModule.pm line 10
Therefore, one must not assume that line 10 was the only error that exists in the Perl module. Once the error is fixed on line 10, be prepared to see more subsequent syntax errors, if they exist.

Replies are listed 'Best First'.
Re: Non-traditional, Line by Line Compilation in Perl
by Anonymous Monk on Dec 07, 2011 at 11:39 UTC
      Example, all oneliners :D
      $ perl -c -e " use strict; use warnings; BEGIN { $sumeet = 1; } $grove +r = 1; } " Global symbol "$sumeet" requires explicit package name at -e line 1. BEGIN not safe after errors--compilation aborted at -e line 1. $ perl -c -e " use strict; use warnings; BEGIN { our $sumeet = 1; } $g +rover = 1; } " Global symbol "$grover" requires explicit package name at -e line 1. Unmatched right curly bracket at -e line 1, at end of line syntax error at -e line 1, near "; }" -e had compilation errors. $ perl -c -e " use strict; use warnings; BEGIN { our $sumeet = 1; } $g +rover = 1; " Global symbol "$grover" requires explicit package name at -e line 1. -e had compilation errors. $ perl -c -e " use strict; use warnings; BEGIN { our $sumeet = 1; } ou +r $grover = 1; " -e syntax OK
      Agreed, compilation would be based on statements, separated by semicolon!

        Agreed, compilation would be based on statements, separated by semicolon!

        We don't need no stinkin semicolons !:)

        $ perl -c -e " use strict; use warnings; { $foo = 1 } { $bar }} " Global symbol "$foo" requires explicit package name at -e line 1. Global symbol "$bar" requires explicit package name at -e line 1. Unmatched right curly bracket at -e line 1, at end of line syntax error at -e line 1, near "}}" -e had compilation errors.
        $ perl -e " use strict; use warnings; { our $foo = 1 } { our $bar } p +rint 666" 666
Re: Non-traditional, Line by Line Compilation in Perl
by JavaFan (Canon) on Dec 07, 2011 at 17:25 UTC
    I do not think you are correct.
    $ (echo '};'; echo '{};'; echo '};') | perl -c Unmatched right curly bracket at - line 1, at end of line syntax error at - line 1, near "}" Unmatched right curly bracket at - line 3, at end of line syntax error at - line 3, near "}" - had compilation errors. $
    Parsing did not stop at finding the first syntax error.
Re: Non-traditional, Line by Line Compilation in Perl
by choroba (Cardinal) on Dec 07, 2011 at 11:19 UTC
    Should I ever get engaged in C compiling, I would try to remember :-)
Re: Non-traditional, Line by Line Compilation in Perl
by ambrus (Abbot) on Dec 08, 2011 at 07:01 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://942215]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-18 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found