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

Would a long-running perl script hang if one of its used package (.pm) files was edited while the script was running? This is perl, v5.8.5 built for sun4-solaris-thread-multi-64.
  • Comment on Script hangs after editing package file?

Replies are listed 'Best First'.
Re: Script hangs after editing package file?
by merlyn (Sage) on Sep 14, 2005 at 01:35 UTC
Re: Script hangs after editing package file?
by rolfy (Acolyte) on Sep 14, 2005 at 02:19 UTC

    Firstly, I should say that I don't know for sure...

    My assumption would be, if you have 'use' or 'require' at the start of your script, then you've already got that module loaded and it won't be loading again until the program is re-started. Certainly this has been my observation with modules of my own that I've modified during developing various tools...

    Safest bet - stop the application, make your changes, restart application.

    If you want to know for sure, set up a similar scenario, have the module print 'foo' every second. Start the app, modify the module to print 'bar' and see if it effects it

Re: Script hangs after editing package file?
by fireartist (Chaplain) on Sep 14, 2005 at 08:31 UTC

    While merlyn is correct, the tricky bit is "the .pm file once processed is not consulted again".

    Remember that use is compile-time and require is runtime.

    If the file is use'd, then everything will be okay. If the file is require'd, then it won't be read from disk until your code gets to that point. Also, if there is a use or require within a string eval, the file won't be read from disk until that point in the runtime.

    But yes, after a file has been read from disk once, it won't be read again during the life of the script.

    However is the script using fork? I've no idea whether forked processes work the same.