I am trying to use part of the CGI module doc about giving a new
object the parameters saved in a file.
I am able to save the parameters to a file:
> SAVING THE STATE OF THE SCRIPT TO A FILE:
>
> $query->save(FILEHANDLE)
and I'm able to add to the parameters that an object already has:
> $query->param(-name=>'foo',-value=>'the value');
I'm able to also initialize the query object from an associa
tive array reference:
> $query = new CGI( {'dinosaur'=>'barney',
> 'song'=>'I love you',
> 'friends'=>[qw/Jessica George Nancy/]}
> );
But I'm NOT able to use this:
> CREATING A NEW QUERY OBJECT FROM AN INPUT FILE
>
> $query = new CGI(INPUTFILE);
With the code:
#!/usr/local/bin/perl -w
use CGI;
# set a parameter and save it in a file
open (OUT,">/home/greg/test.out") or die "No open greg/test.out: $!";
$p = new CGI;
$p->param(-name=>'ID',-value=>'23423456');
$p->save(OUT);
close OUT;
# reopen for reading
open (IN,"/home/greg/test.out") or die "No params from test.out: $!\n";
$q = new CGI;
print $q->header,
$q->start_html;
foreach $name ($q->param) {
print ($name, "=", $q->param($name), $q->p);
}
print $q->end_html;
I get in the debugger,
DB<2>
main::(./other.pl:14): $q = new CGI(IN);
DB<2>
main::(./other.pl:16): print $q->header,
main::(./other.pl:17): $q->start_html;
DB<2> x $q
0 CGI::Object=HASH(0x826c1e8)
'.charset' => 'ISO-8859-1'
'.fieldnames' => HASH(0x8297b84)
empty hash
'.named' => 0
'.parameters' => ARRAY(0x82909c0)
0 'keywords'
'keywords' => ARRAY(0x828defc)
0 'IN'
DB<3>
And then as evaluating <IN> shows, the parameters are sitting
there waiting to be read in.
DB<3> x <IN>
0 'ID=23423456
'
1 '=
'
DB<4>
Curiously, this returning of 'keyword' for the parameters is what
the perldoc says to expect if the script was invoked as an
<ISINDEX> request.
So I gave up and inserted this to read from the file myself.
while (<IN>) {
last if $_ =~ m/^=$/;
($name, $value) = split '=';
$q->param(-name => $name, -value => $value);
}
And this works. But why doesn't
$q = new CGI(IN);
work?
--
Greg Matheson All teaching is teaching
Chinmin College, under difficult circumstances.
Taiwan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]