Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Mod_perl & do()

Reply
Thread Tools

Mod_perl & do()

 
 
Mike Mimic
Guest
Posts: n/a
 
      09-13-2003
Hi!

I tryed to use do() function in mod_perl 1.27 but as I found out that
does not work. For example

test.pl:
#!/usr/bin/perl
my $test = 0;
do 'text.cf';
print "Content-type: text/html\n\n";
print $test;

test.cf:
$test = 1;

prints 0 and not 1. Files are in the same directory and there is '.' in
@INC.

scalar eval `cat test.cf` works but I really would not like to use this.

I use this for including configuration data.


Mike

 
Reply With Quote
 
 
 
 
Jay Tilton
Guest
Posts: n/a
 
      09-13-2003
Mike Mimic <(E-Mail Removed)> wrote:

: I tryed to use do() function in mod_perl 1.27 but as I found out that
: does not work. For example
:
: test.pl:
: #!/usr/bin/perl
: my $test = 0;

Declaring that $test with my() gives it file scope...

: do 'text.cf';
: print "Content-type: text/html\n\n";
: print $test;
:
: test.cf:
: $test = 1;

....so that $test is a completely different variable.

 
Reply With Quote
 
 
 
 
Mike Mimic
Guest
Posts: n/a
 
      09-13-2003
Hi!

> Declaring that $test with my() gives it file scope...
>
> : do 'text.cf';
> : print "Content-type: text/html\n\n";
> : print $test;
> :
> : test.cf:
> : $test = 1;
>
> ...so that $test is a completely different variable.


I think that it is not true.

do 'text.cf' should simply include code (like C++ include pragma) so
that the code of the program would be

#!/usr/bin/perl
my $test = 0;
$test = 1;
print "Content-type: text/html\n\n";
print $test;

I have changed the program slightly to show the problem (test.cf is not
loaded).

test.pl:
#!/usr/bin/perl
my $test = 0;
print "Content-type: text/html\n\n";
do 'text.cf';
print $test;

test.cf:
print "Loaded.\n";
$test = 1;

It prints only 0.


Mike


 
Reply With Quote
 
Andreas Kahari
Guest
Posts: n/a
 
      09-13-2003
In article <bTB8b.2563$(E-Mail Removed)>, Mike Mimic wrote:
> Hi!
>
>> Declaring that $test with my() gives it file scope...

[cut]
> I think that it is not true.

[cut]

The manual for 'do' (perldoc -f do) says:

[...] code evaluated with "do FILENAME" cannot see lexicals
in the enclosing scope [...]

--
Andreas Kähäri
 
Reply With Quote
 
Jay Tilton
Guest
Posts: n/a
 
      09-13-2003
Mike Mimic <(E-Mail Removed)> wrote:

: do 'text.cf' should simply include code (like C++ include pragma) so
: that the code of the program would be
:
: #!/usr/bin/perl
: my $test = 0;
: $test = 1;
: print "Content-type: text/html\n\n";
: print $test;

Actually, it would be like

#!/usr/bin/perl
my $test = 0;
$main::test = 1; # package variable, not lexical
print "Content-type: text/html\n\n";
print $test;

: I have changed the program slightly to show the problem (test.cf is not
: loaded).
:
: test.pl:
: #!/usr/bin/perl
: my $test = 0;
: print "Content-type: text/html\n\n";
: do 'text.cf';
^^^^^^^
^

: print $test;
:
: test.cf:
^^^^^^^
^

: print "Loaded.\n";
: $test = 1;
:
: It prints only 0.

It would help if the filenames were the same.
Including checks on whether the do() succeeds is always a good idea.

 
Reply With Quote
 
Mike Mimic
Guest
Posts: n/a
 
      09-13-2003
Hi!

Jay Tilton wrote:
> Actually, it would be like
>
> #!/usr/bin/perl
> my $test = 0;
> $main::test = 1; # package variable, not lexical
> print "Content-type: text/html\n\n";
> print $test;


Changing my $test to our $test does the trick.

> It would help if the filenames were the same.
> Including checks on whether the do() succeeds is always a good idea.


Ups. Thanks. It was only a test script but you are right.

Thanks, it works now.


Mike

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mod_perl installed, but mod_perl.so file not created bennett@peacefire.org Perl Misc 2 01-25-2006 10:53 PM
good mod_perl/mysql object oreinted application Bill Warner Perl 1 07-14-2004 11:04 PM
Using IPC::open2 under mod_perl Antonio Perl 0 05-17-2004 12:11 PM
Model 2 framework for mod_perl - Do you know any? Ziya Suzen Perl 0 02-01-2004 07:09 PM
mod_perl errors: prototype mismatch ... during global destruction ian douglas Perl 0 08-18-2003 11:17 PM



Advertisments