Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Changing PM File at Run time

by Anonymous Monk
on Dec 10, 2008 at 07:50 UTC ( [id://729349]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have a PM File in which data is stored from the source file that i select at runtime. In run time if i change the file the data is getting updated in the PM file but the updated data is not executed in the application. Only the data that is loaded at first is getting executed. I am using
 require <file name >
Can any one give me a clue on how to do this?

Replies are listed 'Best First'.
Re: Changing PM File at Run time
by moritz (Cardinal) on Dec 10, 2008 at 08:47 UTC
    Delete it from %INC, and require it again.

    But .pm files aren't the best way to store data. Either use a serialization format like YAML, JSON or CSV or plain text files.

    If it has to be a perl script that holds the data, do EXPR or eval might be more appropriate.

      or even better, embedded perl in a yaml file
Re: Changing PM File at Run time
by Anonymous Monk on Dec 10, 2008 at 08:10 UTC
    perldoc -f require

    Require will not reload an already loaded file.

Re: Changing PM File at Run time
by tsee (Curate) on Dec 11, 2008 at 08:53 UTC

    Check out the Class::Unload module on CPAN. It takes care of almost all the icky details of unloading a module from memory. Afterwards, you can simply reload the module with "require" or "use".

Re: Changing PM File at Run time
by djp (Hermit) on Dec 12, 2008 at 01:16 UTC
    Others have told you how to do this, but I have to say this sounds like a Really Bad Idea. Load the data from a file, not from a .pm.
Re: Changing PM File at Run time
by mrpeabody (Friar) on Dec 13, 2008 at 14:18 UTC
    1) You should put the data in a separate file from your source code.

    2) You can't ask Perl to automatically update your variables when your data file changes. You have to do it by hand, perhaps on-demand or by checking the file's last-modified time on a regular basis.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://729349]
Approved by GrandFather
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found