CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Global symbol "$name" requires explicit package name

 



crfreaks
New User

Mar 22, 2014, 7:55 PM

Post #1 of 5 (1934 views)
Global symbol "$name" requires explicit package name Can't Post

hello,
I am just starting out and was just tring out a lesson i found and well i can not get it to work.

syntax error, near "my"
Global symbol "$name" requires explicit package name


Code
 
#!/usr/bin/perl -w
use strict;
use warnings;

print "Hello World\n";
print "What is your name?\n;"

my $name = readline STDIN;
chomp ($name);
print "Hello $name how may i help you today?\n"



BillKSmith
Veteran

Mar 22, 2014, 9:23 PM

Post #2 of 5 (1931 views)
Re: [crfreaks] Global symbol "$name" requires explicit package name [In reply to] Can't Post

Note location of semicolon.

Code
print "What is your name?\n";

Good Luck,
Bill


crfreaks
New User

Mar 22, 2014, 9:32 PM

Post #3 of 5 (1929 views)
Re: [BillKSmith] Global symbol "$name" requires explicit package name [In reply to] Can't Post

Wow i looked at that line at least 30 times and did not see that error.. Thanks


Laurent_R
Veteran / Moderator

Mar 23, 2014, 5:16 AM

Post #4 of 5 (1927 views)
Re: [crfreaks] Global symbol "$name" requires explicit package name [In reply to] Can't Post


In Reply To
Wow i looked at that line at least 30 times and did not see that error.. Thanks


The lesson is that when you get a compile error on line n, you must look not only at line n but also at line n - 1 and also at the previous lines (sometimes the error is 10 or more lines above the line at which the compiler choked).


FishMonger
Veteran / Moderator

Mar 23, 2014, 8:49 AM

Post #5 of 5 (1925 views)
Re: [crfreaks] Global symbol "$name" requires explicit package name [In reply to] Can't Post


Quote

Code
my $name = readline STDIN;


That is normally written as:

Code
my $name = <STDIN>;


You can also combine it with the chomp statement.

Code
chomp (my $name = <STDIN>);


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives