in reply to memory persistance

Not a module, but...

#!/usr/bin/perl use strict; use warnings; use 5.012; BEGIN: recover_var(); # main here # ... insert your existing code for getting the value here # Since you didn't tell us the variable name, we'll use $var and assum +e you've used it my $var; say "(\t\t Simulating execution of existing..."; say "\t\t code to obtain a (new) value for \$var"; say "\t\t and NOW simulating that said execution is complete. \t)\n"; $var += int(rand(113)); say "\n\tTake a pencil and write the current value of \$var, $var, on +your yellow sticky."; say "\t Otherwise, the value of \$var will disappear when the RAM used + by \n\t this script is returned to the OS on termination of the scri +pt./n"; say "\n\t\t\tTerminating..."; exit; sub recover_var { if ( !$var ) { print "\n\t Find your yellow sticky (you did write down the old va +lue, didn't you?) \n\t and enter the last \$var found on the sheet\n\ +t or '0' if no sticky is found: "; chomp ($var = <>); say "\n The last known value of \$var was $var.\n"; return; } }

Tested, but may not be suitable for purchaser's application. No warranty of fitness implied.

Despite the actual syntax error (the begin block that isn't), this passed perl -c ... with flying colors. Expanding on the note above, this is NOT suitable for OP's need, but taken litterally, OP asked for a way to keep a variable in memory after script termination... so here's a way, albeit with "dead tree RAM".

:-)

Replies are listed 'Best First'.
Re^2: memory persistance
by splicer (Novice) on Aug 26, 2011 at 21:59 UTC

    @ww:

    I think your code needs error handling. You should be tossing an exception if the user chooses non-sticky paper or paper of a different color.

      ...and if user selects a recording implement other than a pencil?