Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'm trying to reload parameters to a form via restore_parameters(). Example:
use strict; if (defined($button) eq 'Restore') { open (IN,param('savefile')) || die "Can't open file to restore: $!"; restore_parameters("IN"); close(IN); }
My script is function-oriented (not object-oriented), so I'm finding it a little tricky in getting the form to load the contents of the file. Lets say one field in the saved file is:
date=03-MAY-2002
and the field on the form is defined as:
textfield('date','',30)
How does one get the latter updated? Many thanks in advance, Stacy Mader.

Replies are listed 'Best First'.
Re: recalling state with restore_parameters
by tachyon (Chancellor) on May 03, 2002 at 10:50 UTC

    Loose the quotes around "IN". IN and "IN" are not the same. Unquoted IN is filehandle *kind of for CGI.pm purposes* whereas "IN" is a quoted string. Normally you pass a file handle as a glob like *IN but CGI.pm is *unique* in terms of some of its methodology and interface:

    open (IN,param('savefile')) || die "Can't open file to restore: $!"; restore_parameters(IN); close IN;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: recalling state with restore_parameters
by rinceWind (Monsignor) on May 03, 2002 at 10:10 UTC
    I presume that you are using the CGI.pm module. If you use its save method to save, when you come to restore, pass a file handle in to the new constructor and voila. See the core documentation on CGI.pm.

    Don't be scared by the OO stuff. It's not that difficult to use. You don't actually need to understand the underlying mechanisms in order to use CGI.pm's object features, and in fact it's a good introduction to object orientated programming.