in reply to Re^2: Caching files question
in thread Caching files question

BrowserUk and graff,
Thank you very much, I think this is exactly what I need.
graff,
please let me know what you mean by "using lexically scoped file handles". You mean out of scope of sub myOpen()?
What I am doing is I am calling Script3.pl from Script2.pl from Script1.pl and files are opened inside Script3.pl. So does it mean that I have to open files in external Script1.pl?
Am I right that files will not be cached any more once I stop external script?

Replies are listed 'Best First'.
Re^4: Caching files question
by graff (Chancellor) on Aug 17, 2008 at 18:57 UTC
    please let me know what you mean by "using lexically scoped file handles".

    I'm just saying that if your code is currently written like this:

    open( FH, "<some/path.name" ); while (<FH>) { ... } close FH;
    It will have to be changed to something like this:
    my $fh = myOpen( "<", "some/path.name" ); while (<$fh>) { ... } close $fh;
    (In other words, you need to use a scalar variable instead of a GLOB as the file handle, and as a rule, scalar variables should be lexically scoped by declaring them with "my".)

    No, you don't have to open the files directly in your Script1.pl; it will be best for Script3.pl to have the %cache hash all to itself, as well as all the file opening and reading. Be sure to use strict; and declare with "my".

    Naturally, when your "main" script finishes and exits, all the ram it used is returned to / freed by the OS, no matter how many script files and data files were loaded by your script while it was running. (If you were referring to something else in your last question, I'm sorry if I misunderstood.)