On Jul 21, 2004, at 8:35 AM, Paul Smith wrote:

Dear All

I am trying to run the script below, but I always get the following error:

[EMAIL PROTECTED] scripts]$ secondperl
Global symbol "$greeting" requires explicit package name at /home/paulus/scripts/secondperl line 6.
Global symbol "$greeting" requires explicit package name at /home/paulus/scripts/secondperl line 7.
Execution of /home/paulus/scripts/secondperl aborted due to compilation errors.

Easy enough.

The script is:

#!/usr/bin/perl
use warnings;
use strict;

Above, you are asking Perl to make you play by the Good Programmer rules. One of those rules is, you must declare a variable before using it.


$greeting = "World";

Here you use an undeclared variable. Usually, you'll declare a variable with "my", so change to above line to:


my $greeting = 'World';

Hope that helps.

James

print "It matches\n" if "Hello World" =~ /$greeting/;


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to