How do I thaw and retrieve data from a "Storable file". Here's is the code I'm using for the CGI backend, it seem to work? Thanks for you time David
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;

In reply to Storable: freeze/unfreeze by david.jackson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.