in reply to How do you save a perl script?
However, if you really wanted to replace the currently running script on exit, then do something like:use strict; my $persistentVar = $defaultvalue; if( -e $persistentStateFile ) { open FH, $persistentStateFile or die "Failed to open '$persistentStateFile': $!"; local $/, $@; my $ps = <FH>; eval $ps; die $@ if $@; } END{ open FH, "> $persistentStateFile" or warn "Failed to open '$persistentStateFile': $!" and exit(1); print FH Data::Dumper->Dump( [$refToPersistentVar], ['nameofpersiste +ntvar'] ) or warn "Failed to print persistent data, $!" and exit(1); close FH or warn "Failed to close $persistentStateFile, $!" and exit(1); }
I don't know if that would work, I wouldn't even try. But if you want, go for it.END { open FH, "< $0" or warn "Failed to preserve state... couldn't open + '$0', $!" and exit(1); local $/; $_ = <FH>; s/my \$var=$oldvalue/my \$var=$var/m; open FH, "> $0" or warn "Failed to preserve state... couldn't writ +e to '$0', $!" and exit(1); print FH $_; close $file; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do you save a perl script?
by Dominus (Parson) on Mar 25, 2001 at 19:52 UTC | |
by Adam (Vicar) on Mar 26, 2001 at 04:58 UTC |