How do I display perl syntax warnings?



  • You can display warnings in two ways.

    Inside the script

    $ vi yourprog.pl
    #!/usr/bin/perl
    use warnings;
    

    or

    From the command line

    $ perl -w ./yourprog.pl
    

    The -w option can be entered at the end of the first line in the script like this:
    #!/usr/bin/perl -w

    This is code with an intentional spelling error.

    #!/usr/bin/perl
    use warnings;
    pint "Hello, world!\n"
    

    Running the code with perl warnings, you will see:

    $ perl hw.pl
    Unquoted string "pint" may clash with future reserved word at hw.pl line 3.
    String found where operator expected at hw.pl line 3, near "pint "Hello, world!\n""
    	(Do you need to predeclare pint?)
    syntax error at hw.pl line 3, near "pint "Hello, world!\n""
    Execution of hw.pl aborted due to compilation errors.
    

    Note: The -w acts on the entire program and the "use warnings;" acts just on the file where it is included.


Log in to reply
 

© Lightnetics 2024