Perl Script Debugging

Problem scenario:  You are running a Perl program and getting an error "syntax error at line x, near ...
Global symbol "$foo" requires explicit package name at line x..."

Solution:  Find line x - 1, that is, the line before x.  This line may not have a semicolon.  Semicolons are not needed if the Perl script is one line.  Semicolons are not needed for "sub main" declaration lines with a line with just a brace (either "{" or "}").  Perl debugging may not come as easily as Python or Ruby.  But Perl has numerous features.  

By itself the error 'Global symbol "$foo" requires explicit package name at line x...' could be the result of trying to use a variable name that has not been declared.  Make sure you have not made a typo in referring to a declared variable.

Here is a sample Perl script that reads in user input and assigns it to a variable named "$foo":

use strict;
use warnings;

sub main
    print "Please enter a string and press enter: ";

    my $foo = <STDIN>;

    print "You entered: $contin";


Leave a comment

Your email address will not be published. Required fields are marked *