Hi All, Just got in and read all your answers. Let me start by saying for the X times, I am not using strict / warnings due to my manager who decided it as policy (since he wrote all the code without it, and adding it will only make things worse...all variables declaring and stuff he wrote in the past)
As for pt / mm / in as future to be reserved words well, I will then refer you to the article I used for creating PDF files: http://rick.measham.id.au/pdf-api2/ Where he was using these words, my idea came when I wanted to create a common module for all my reports with same constants.... As for pt / mm / in as being Bareword, I understood it when I run the little code I wrote...but still I need these constants to be shared with the other files -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Gabor Szabo Sent: Friday, September 04, 2009 12:46 PM To: Perl in Israel Subject: Re: [Israel.pm] constants On Thu, Sep 3, 2009 at 4:48 PM, Berler Chanan<[email protected]> wrote: > Hi All, > > Question for you people: > I have got a 2 files like these: one if a perl module, and the other is a > script using require to include the file. > Q: why pt is not defined in Myscript.pl file, although I used the required > ? > Thanks > Chanan > > common_pdf.pm > > ======================= > use constant pt => 1; > 1; > > Myscript.pl > ======================== > require "common_pdf.pm"; > > my $lv_num = pt; > print $lv_num; > For the first few times when someone asks a question we try to be friendly and tell them to use strict; and use warnings; in their code. Then we ask them to at least give us the error message they see and the expected output. I think you have been around for enough time to know this so don't be surprised if people will start to disregard your question or start to flame you. So let's see what could you do: 1) running $ perl Myscript.pl and telling us that the output is 'pt' while you expected it to be 1 2) runnint $ perl -w Myscript.pl and telling us you get the following warning Unquoted string "pt" may clash with future reserved word at Myscript.pl line 8. 3) run $ perl -w Myscript.pl 2> err.txt and then $ splain err.txt You get the diagnostics of the warning: Unquoted string "pt" may clash with future reserved word at Myscript.pl line 8 (#1) (W reserved) You used a bareword that might someday be claimed as a reserved word. It's best to put such a word in quotes, or capitalize it somehow, or insert an underbar into it. You might also declare it as a subroutine. It might not help much to you but at least if you tell us you read this, we see that you made an educated effort to locate the source of the problem. You can also understand it is a bareword which means perl thinks pt is actually the string "pt" That at least explains why is the output "pt" 4) You could add use strict; use warnings; and run perl Myscript.pl you would get: Bareword "pt" not allowed while "strict subs" in use at Myscript.pl line 8. Execution of Myscript.pl aborted due to compilation errors. It still not might help you but will prove that you at least learned from our previous responses. The problem is that "require" is executed during run time, by that time perl compled the pt in Myscript.pl and decided it must be a bareword string. You need to explicitly say that pt is a function by writing pt() (you know that use constant actually creates a function right? or you need to make sure command_pdt.pm is loaded before perl goes on compiling the rest of the Myscript.pl so it will already see the use constant before it sees the use of pt. You can do that by putting it in a BEGIN block. BEGIN { require "common_pdf.pm"; } my $lv_num = pt; print $lv_num; I hope you slowly will learn that using strict and warnings can save a lot of time and a lot of embarrassment. Gabor _______________________________________________ Perl mailing list [email protected] http://mail.perl.org.il/mailman/listinfo/perl No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.5.409 / Virus Database: 270.13.79/2348 - Release Date: 09/05/09 17:50:00 _______________________________________________ Perl mailing list [email protected] http://mail.perl.org.il/mailman/listinfo/perl
