more useful options | |
PerlMonks |
Re: Saving sub routines.. Is it possible?by grinder (Bishop) |
on Apr 05, 2008 at 15:45 UTC ( [id://678539]=note: print w/replies, xml ) | Need Help?? |
Can this be done? This is Perl, of course it can be done. In this particular case, we need to avail ourselves of demerphq's most excellent Data::Dump::Streamer. Even then, a major imposition is that you have to use package variables, since lexical variables can't be injected into scope from an eval. You can take your data structure and dump it out, being careful to name it so that you can find it again:
This writes the sub to STDOUT. You will probably want to write it to a filehandle; read the documentation to find out how to do that. You can then thaw the subroutines by eval'ing the resulting dumped code:
You will observe that $var1 changes its value after calling the subroutine. Be that as it may, this is a pretty odd thing to want to do. If it's not impolite, I'm curious to know what you want to use it for. • another intruder with the mooring in the heart of the Perl
In Section
Seekers of Perl Wisdom
|
|