Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Mod_perl & do()

    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

    Mike Mimic Guest

  2. Similar Questions and Discussions

    1. mod_perl and GD
      Using: Apache/2.0.48 (Unix) mod_perl/1.99_13-dev Perl/v5.8.3 gd version 2.0.22 GD.pm version 2.12 on Redhat 9: 2.4.20-28.9smp
    2. mod_perl 1.99 Apache 2.0.48
      Hello, I built a sever with apache and perl (cgi), and i used the mod_perl to boost my server, it actually works 4x time faster with mod_perl. ...
    3. mod_perl: my $var=1 if ...
      I'm having trouble understanding something in mod_perl. The sub handler is: sub handler { ...stuff deleted... my $var=1 if...
    4. [PHP] PHP and mod_perl
      Walter Torres wrote: Looks like Apache 2? Not too familiar with that (still using 1.3.x myself), but it seems to me that SetHandler may be...
    5. PHP and mod_perl
      Anyone have any idea why I can't run PHP and mod_perl in the same web structure? I am getting this in my error log... 2508:...
  3. #2

    Default Re: Mod_perl & do()

    Mike Mimic <ppagee@yahoo.com> 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.

    Jay Tilton Guest

  4. #3

    Default Re: Mod_perl & do()

    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


    Mike Mimic Guest

  5. #4

    Default Re: Mod_perl & do()

    In article <bTB8b.2563$2B6.601880@news.siol.net>, 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
    Andreas Kahari Guest

  6. #5

    Default Re: Mod_perl & do()

    Mike Mimic <ppagee@yahoo.com> 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.

    Jay Tilton Guest

  7. #6

    Default Re: Mod_perl & do()

    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

    Mike Mimic Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139