Arun Tv has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I got an issue while loading files using "require" Function.
When I am loading same file multiple times the updations are not reflected.
See the below script
#!/usr/local/bin/perl require "file1"; print "name-1 == $NAME\n"; require "file2"; print "name-2 == $NAME\n"; require "file1"; print "name-1 == $NAME\n";
file1
------
$NAME = "John";


file2
------
$NAME = "Kent";


The Output I am getting is
name1 = John name2 = Kent name1 = Kent

How can I overcome this ?

Replies are listed 'Best First'.
Re: resetting the "require" Function.
by Fletch (Bishop) on Nov 03, 2008 at 15:57 UTC

    Delete the corresponding value from %INC and require won't think it's already been loaded. Or use do instead which is intended for this sort of thing already.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: resetting the "require" Function.
by almut (Canon) on Nov 03, 2008 at 15:57 UTC

    Works as designed :) - require keeps track of what files it has already loaded...  Use do if you want to reread the same source file multiple times.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: resetting the "require" Function.
by chromatic (Archbishop) on Nov 03, 2008 at 21:48 UTC
    How can I overcome this ?

    If all you're doing is setting data-driven values, consider a configuration file and any of the good configuration processing modules on the CPAN. Config::Auto and Config::Any are worth exploring.

      HI MONKS,
      Cooool
      That was a lot more info than I expected.
      --------------
      TV ARUN TV