develooper Front page | perl.perl5.porters | Postings from March 2007

Re: file reloading

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
March 29, 2007 04:14
Subject:
Re: file reloading
Message ID:
460B9F67.3080407@pobox.com
Irene Ladyko wrote:
> Hello, perl5-porters.
> 
> I use embeded perl (version 5.8.8) interpreter in my application.
> 
> Situation:
> 1. I load test.pm file per eval_pv function.
>                         perl_eval_pv ("require 'test.pm';", FALSE);
> 2. Then call IncreaseGlobalVariable. It increases by 1.
> 3. Then I reload test.pm file again. As I understand reloading, it
> means variable reloading too, i.e. int_var variable must be set on 75.
> But it doesn't happened.

First, let's get rid of the embedding.  Its just distracting from the real
problem.  You're doing this:

    require 'test.pm';
    IncreaseGlobalVariable();
    print $int_var, "\n";

    require 'test.pm';
    print $int_var, "\n";

If you look in "perldoc -f require" you find this:

    Note that the file will not be included twice under the same
    specified name.

require isn't just a simple "load and eval this file", it has some smarts so
you don't reload the same code twice.  For that you want "do".

    do "test.pm";
    IncreaseGlobalVariable();
    print $int_var, "\n";

    do "test.pm";
    print $int_var, "\n";


> Questions:
>           What must I do to reload file completely. (Global variables from
> other files will not be reloaded). Please, point me to solution.
> 
> 
> //----------test.pm---------------
> $int_var = 75;
> 
> sub IncreaseGlobalVariable
> {
>         $int_var = $int_var + 1;
>         $int_var;
> }
> 1;
> //--------------------------------
> 


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About