in reply to Re: CGI script bringing its own data
in thread CGI script bringing its own data

Thanks for your advice, Liz. Freezing $data would indeed make sense to me, as having the data at hand without reading it from a file is what I'm trying to do. I initially thought about useing Storable, but that would still leave a file for loading and really wouldn't make any sense. Basically, I'd like to do the following: Instead of
open (my $in_fh, $infile) or die; local $/; # enable slurping mode my $data = <$in_fh>; close $in_fh;
I'd like to do
my $data = handoverthedata(); (...) sub handoverthedata{ # Inlined data starts here # and gets stored in my $foo... # Data # Data # Data # Data # Data # Data # Data # Data # Data # Data # Data # Data # Data return $foo; }
Any ideas on how to do it? I think I've seen similar constructs in C (though I don't know any C), and I'd be surprised if there wasn't a "canonical" way to do it in Perl. -hacmac

Replies are listed 'Best First'.
Re: Re: Re: CGI script bringing its own data
by liz (Monsignor) on Sep 03, 2003 at 10:56 UTC
    But why would you want it to do that? It's not going to help you much.

    But anyway, maybe the following will do the trick if you only have one file:

    1. add a line with __DATA__ at the end of your script.
    2. save the script and make sure the editor doesn't keep it open
    3. then in the shell, do a "cat pngfilename >>yourscript" (assuming you have a *nix here. If you have Win32, it might work in a command window by replacing "cat" with "type")
    4. open the script again, you should see a lot of garbage at the end, don't touch that.
    5. Remove the open() and close() calls.
    6. replace my $data = <$in_fh>; with my $data = <DATA>;

    I haven't tried it myself. I hope your editor doesn't mangle the data. If it does, then keep a clean copy without the data at the end and create a final copy each time you made changes.

    Hope this helps.

    Liz