david.jackson has asked for the wisdom of the Perl Monks concerning the following question:
CGI backend (and runtime errors): Use of uninitialized value in read at ./hashbrowns.cgi line 10 and 27 (#1)
#!/usr/bin/perl -w use strict; use diagnostics; use Storable qw( nfreeze thaw ); my ($server,$ipaddr,$funct); my ($FORM,$value,$pair,@pairs,$buffer,$name,%FORM); ###################################################### print "Content-type:text/html\n\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\n/ /g; # replace newlines with spaces $value =~ s/\r//g; # remove hard returns $value =~ s/\cM//g; # delete ^M's $FORM{$name} = $value; } ######################################################### # open SERVERS, ">>/tmp/homefries.db" or die "Hold on there buckaroo: $!\n"; my $boxen = { 'host' => "$FORM{hostess}", 'address'=> "$FORM{ipaddr}", 'funct' => "$FORM{funct}", }; my $sirinfo = nfreeze( $boxen ); $_ = unpack("H*", $sirinfo) ."\n"; print SERVERS $_; print "$boxen->{host}\n"; print "$boxen->{address}\n"; print "$boxen->{funct}\n"; # close SERVERS; exit;
My attemp at thawing datafile Runtime error: Not an ARRAY reference at ./hashbrowns.pl line 11, <SERVERS> line 1 (#1)
#!/usr/bin/perl -w use strict; use diagnostics; use Storable qw( nfreeze thaw ); my ($server,$ipaddr,$funct,$boxen,@fields); open SERVERS, "/tmp/homefries.db" or die "Hold on there buckaroo: $!\n"; while (<SERVERS>) { my $frozen = pack "H*", $_; my $fields = thaw($frozen); my ($server,$ipaddr,$funct) = @$fields; } close SERVERS; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: Storable: freeze/unfreeze
by Ovid (Cardinal) on Oct 15, 2001 at 21:51 UTC | |
|
Re: Storable: freeze/unfreeze
by lestrrat (Deacon) on Oct 15, 2001 at 21:29 UTC | |
|
Re: Storable: freeze/unfreeze
by Maclir (Curate) on Oct 15, 2001 at 21:39 UTC | |
|
see Revised Storable:
by david.jackson (Novice) on Oct 16, 2001 at 00:27 UTC |