Perl Error Requires Specific Package Name
Contents |
PerlNews Q&A Tutorials Poetry RecentThreads NewestNodes Donate What'sNew on Jun 16, 2003 at 22:59UTC ( #266329=perlquestion: print w/replies, xml ) Need Help?? Theo has asked for the wisdom of the Perl Monks concerning the perl requires following question: This should be easy (for most Monks). This one of
Perl Declaring Variables
my first attempts at modifying someone else's code. The code creates a hyperlinked list of images and thumbnails perl declare global variable in one long column. I'm trying to use a table sturcture to present the list in two columns. The var $counter is to distinguish between odd and even columns so declared symbol I can properly open & close the table rows. The first line returns the error message: Global symbol "$counter" requires explicit package name at TnImg.pl line 16. It gives the same message if the var is preceeded by 'my'. I'm using strict and the -w. Can some kind soul point me towards the solution? $counter = 0; # add link
Perl Use Vars
text to each filename foreach my $name (@filenames) { if ($counter % 2){ #odd rows $name = qq{
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site bareword not allowed while "strict subs" in use at About Us Learn more about Stack Overflow the company Business Learn more about 🅴 hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join
Perl Our
the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Global symbol requires explicit package http://www.perlmonks.org/?node_id=266329 name up vote 19 down vote favorite 4 Global symbol requires explicit package name? Why has this occurred and what are various cases that can cause this error? perl share|improve this question edited Aug 3 '13 at 17:13 tchrist 59.9k2187143 asked Jun 29 '10 at 14:01 Tree 2,432174878 1 Sample perl code? See stackoverflow.com/q/4257179/10468 or search for questions on perl modules. See also (offsite) http://stackoverflow.com/questions/3141412/global-symbol-requires-explicit-package-name sitepoint.com/forums/… –DarenW Apr 12 '12 at 17:31 add a comment| 6 Answers 6 active oldest votes up vote 22 down vote accepted Have a look at perldiag: Global symbol "%s" requires explicit package name (F) You've said "use strict" or "use strict vars", which indicates that all variables must either be lexically scoped (using "my" or "state"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::"). share|improve this answer answered Jun 29 '10 at 14:19 musiKk 9,11512855 add a comment| up vote 16 down vote It may also happen when the statement before is not complete. use strict; sub test; test() # some comment my $x; perl now complains with following error message: my " Global symbol "$x" requires explicit package name The error is not in the declaration of "my", but at the missing semicolon (;) at test(). share|improve this answer answered Jan 15 '12 at 14:50 koppor 4,95323852 Thank you! I was tearing my hair out. –Zack Sep 1 at 23:52 add a comment| up vote 4 down vote In order to specifically say what caused it in your code, you wou
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site http://stackoverflow.com/questions/16668956/error-global-symbol-requires-explicit-package-name About Us Learn more about Stack Overflow the company Business Learn more about http://stackoverflow.com/questions/4257179/why-does-perl-say-global-symbol-symbol-requires-explicit-package-name-at-progr hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error-global symbol requires explicit perl error package name up vote 1 down vote favorite I am trying print all the values of a database table on a webpage in a table format.I am using a perl file having .cgi extension.Whenever i try to run the code i get the error "global symbol requires explicit package name".The rows of the database table should be displayed onLoad but it's not happening.. I have perl error requires tried a lot but can't understand whats wrong with the code.. Please Help.. Code of people.cgi file .. #!/usr/bin/perl use CGI; use DBI; use strict; use warnings; print "Content-type:text/html\r\n\r\n"; #$q = CGI->new; #print $q->header; my $dsn = "DBI:mysql:Demo:localhost"; # Data source name my $username = "mint"; # User name my $password = "MINT123"; # Password my $dbh; my $sth; # Database and statement handles $dbh = DBI->connect($dsn, $username, $password); $sth = $dbh->prepare("SELECT * from people"); $sth->execute(); print "
ganesh
"; print "ID | Name of People Involved | Position | Roles(A user can have multiple roles) | Notes | ||
---|---|---|---|---|---|---|
$$href{'id'} | "; print "$$href{'name'} | "; print "$$href{'pos'} | "; print "$$href{'role'} | "; print "$$href{'notes'} | "; #print ""; #print " | "; print " |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why does Perl say Global symbol “SYMBOL” requires explicit package name at PROGRAM.pl line X? up vote 6 down vote favorite I´m writing my first programs in Perl, and wrote this: use strict; use warnings; $animal = "camel"; print($animal); When I run it, I get these messages from the Windows command-line: Global symbol "animal" requires explicit package name at stringanimal.pl line 3 Global symbol "animal" requires explicit package name at stringanimal.pl line 4 Please, could anyone what these messages mean? perl share|improve this question edited Aug 14 '13 at 4:16 the Tin Man 110k22135206 asked Nov 23 '10 at 14:47 Peterstone 1,18982743 add a comment| 2 Answers 2 active oldest votes up vote 24 down vote accepted use strict; forces you to declare your variables before using them. If you don't (as in your code sample), you'll get that error. To declare your variable, change this line: $animal = "camell"; To: my $animal = "camell"; See "Declaring variables" for a more in-depth explanation, and also the Perldoc section for use strict. P.S. Camel is spelt "camel" :-) Edit: What the error message actually means is that Perl can't find a variable named $animal since it hasn't been declared, and assumes that it must be a variable defined in a package, but that you forgot to prefix it with the package name, e.g. $packageName::animal. Obviously, this isn't the case here, you simply hadn't declared $animal. share|improve this answer e