- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Error in perl: Global symbol requires explicit pa...
Operating System - HP-UX
1821983
Members
3364
Online
109638
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2004 05:53 PM
тАО05-04-2004 05:53 PM
Hi,
I am trying to learn perl and before that I have installed perl5.8 in hp-ux 11.0 OS. Here is the
swlist output: perl D.5.8.0.B Perl Programming Language
After perl installation everything is /opt/perl/ directory. Below are the bin,lib,man,html dir.
/opt/perl/bin ;/opt/perl/html;/opt/perl/lib ; /opt/perl/man
Earlier i have perl 4 in my system.I have moved earler perl found in /usr/local/bin and
/usr/contrib/bin to perl4.0.
Now to compile perl program and to get all features of perl program what sort of changes or
configuration do i need to perform?
I am getting below error while compiling one perl program.
""""
Global symbol "%words" requires explicit package name at qsn_ansugng_qw.pl line 6
Global symbol "$name" requires explicit package name at qsn_ansugng_qw.pl line 13
syntax error at qsn_ansugng_qw.pl line 22, near "$words("
Global symbol "$guess" requires explicit package name at qsn_ansugng_qw.pl line 26
Global symbol "$secretword" requires explicit package name at qsn_ansugng_qw.pl line 26
... etc
"""""
Below is my program.
#!/opt/perl/bin/perl -w
use strict;
%words = qw(
fred camel
barney llama
betty alpaca
wilma alpaca
);
print "What is your Name?" ;
$name =;
chop ($name);
if ( $name eq "Tapas" )
{
print "Hello, $name! How good of you to be here!\n";
}
else
{
print "Hello, $name!\n";
$secretword = $words($name);
print "What is the secret word !";
$guess=;
chop ($guess);
print "Invalid Guess!! Try Again !!!\n";
print "What is the secret word !";
$guess=;
chop ($guess);
}
}
Will appreciate if get proper guidance not only for this but also how to learn perl properly.(Full online help)
Thanx in advance.
Rgds
Tapas
I am trying to learn perl and before that I have installed perl5.8 in hp-ux 11.0 OS. Here is the
swlist output: perl D.5.8.0.B Perl Programming Language
After perl installation everything is /opt/perl/ directory. Below are the bin,lib,man,html dir.
/opt/perl/bin ;/opt/perl/html;/opt/perl/lib ; /opt/perl/man
Earlier i have perl 4 in my system.I have moved earler perl found in /usr/local/bin and
/usr/contrib/bin to perl4.0.
Now to compile perl program and to get all features of perl program what sort of changes or
configuration do i need to perform?
I am getting below error while compiling one perl program.
""""
Global symbol "%words" requires explicit package name at qsn_ansugng_qw.pl line 6
Global symbol "$name" requires explicit package name at qsn_ansugng_qw.pl line 13
syntax error at qsn_ansugng_qw.pl line 22, near "$words("
Global symbol "$guess" requires explicit package name at qsn_ansugng_qw.pl line 26
Global symbol "$secretword" requires explicit package name at qsn_ansugng_qw.pl line 26
... etc
"""""
Below is my program.
#!/opt/perl/bin/perl -w
use strict;
%words = qw(
fred camel
barney llama
betty alpaca
wilma alpaca
);
print "What is your Name?" ;
$name =
chop ($name);
if ( $name eq "Tapas" )
{
print "Hello, $name! How good of you to be here!\n";
}
else
{
print "Hello, $name!\n";
$secretword = $words($name);
print "What is the secret word !";
$guess=
chop ($guess);
print "Invalid Guess!! Try Again !!!\n";
print "What is the secret word !";
$guess=
chop ($guess);
}
}
Will appreciate if get proper guidance not only for this but also how to learn perl properly.(Full online help)
Thanx in advance.
Rgds
Tapas
Tapas Jha
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2004 06:39 PM
тАО05-04-2004 06:39 PM
Re: Error in perl: Global symbol requires explicit package name
The errors are due to your "use strict;" statements which imposes stricter behaviour on the perl parser.
In perl-4, one has global symbols, and one could give it a temporary value with 'local', which would restore the original value on end of scope.
In perl-5, these type of values still exist, but now that we have modules, we don't want the variables to `leak' to outside a script. Because variables are refered to by name - though namespace hashes - they will not only be visible to the cruel outside world, but they will also be modifiable (changeable, alterable).
In perl-5 we now have lexical variables, only known to the scope in which they are declared, and these do not live in a namespace hash, but in something called a pad.
Lexical vaiables are declared with the keyword 'my':
my $foo = 1;
my @bar = (1, "test", 3.5, sqrt 4);
my %baz = ( green => '#00ff00', red => '#ff0000');
if no scope is active (a block, or a package), the default scope for a variable is the file (script).
--8<---
#!/opt/perl/bin/perl
use strict;
use warnings; # replaces -w, but much better
my %words = (
fred => "camel",
barney => "llama",
betty => "alpaca",
wilma => "alpaca",
);
print "What is your Name?";
chomp (my $name =); # chomp is a safe chop.
if ($name eq "Tapas") {
print "Hello, $name! How good of you to be here!\n";
}
else {
print "Hello, $name!\n";
my $secretword = $words{$name}; # hashes need braces, no parens
print "What is the secret word !";
chomp ($guess =);
if ($guess ne $secretword) {
print "Invalid Guess!! Try Again !!!\n";
print "What is the secret word !";
chomp ($guess =);
}
}
}
-->8---
# perldoc strict
# perldoc -f chomp
# man perlvar
Enjoy, Have FUN! H.Merijn
In perl-4, one has global symbols, and one could give it a temporary value with 'local', which would restore the original value on end of scope.
In perl-5, these type of values still exist, but now that we have modules, we don't want the variables to `leak' to outside a script. Because variables are refered to by name - though namespace hashes - they will not only be visible to the cruel outside world, but they will also be modifiable (changeable, alterable).
In perl-5 we now have lexical variables, only known to the scope in which they are declared, and these do not live in a namespace hash, but in something called a pad.
Lexical vaiables are declared with the keyword 'my':
my $foo = 1;
my @bar = (1, "test", 3.5, sqrt 4);
my %baz = ( green => '#00ff00', red => '#ff0000');
if no scope is active (a block, or a package), the default scope for a variable is the file (script).
--8<---
#!/opt/perl/bin/perl
use strict;
use warnings; # replaces -w, but much better
my %words = (
fred => "camel",
barney => "llama",
betty => "alpaca",
wilma => "alpaca",
);
print "What is your Name?";
chomp (my $name =
if ($name eq "Tapas") {
print "Hello, $name! How good of you to be here!\n";
}
else {
print "Hello, $name!\n";
my $secretword = $words{$name}; # hashes need braces, no parens
print "What is the secret word !";
chomp ($guess =
if ($guess ne $secretword) {
print "Invalid Guess!! Try Again !!!\n";
print "What is the secret word !";
chomp ($guess =
}
}
}
-->8---
# perldoc strict
# perldoc -f chomp
# man perlvar
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2004 07:39 PM
тАО05-04-2004 07:39 PM
Re: Error in perl: Global symbol requires explicit package name
Thanx Procura. Great!!
Now It's working but not accurately. During compling It was giving error "global symbol requires" and i have changed three lines where chomp was there. Put my eg; chomp (my $guess=
But this program is not matching name, secretword sequesnce. Instead of if condition if you put while then it should terminate when matches but it's not.
Rgds
Tapas
Tapas Jha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2004 07:46 PM
тАО05-04-2004 07:46 PM
Solution
Look at the lines where I inserted 'my' in front of the variable.
To loop till a valid answer is given:
my $secretword = $words{$name};
for (;;) {
print "Hello, $name!\n";
print "What is the secret word !";
chomp ($guess =);
$guess eq $secretword and last;
print "Invalid Guess!! Try Again !!!\n";
}
Enjoy, Have FUN! H.Merijn
To loop till a valid answer is given:
my $secretword = $words{$name};
for (;;) {
print "Hello, $name!\n";
print "What is the secret word !";
chomp ($guess =
$guess eq $secretword and last;
print "Invalid Guess!! Try Again !!!\n";
}
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP