Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: CGI and Storable : explain me this, please.

by rhesa (Vicar)
on Apr 27, 2006 at 02:37 UTC ( [id://545935]=note: print w/replies, xml ) Need Help??


in reply to CGI and Storable : explain me this, please.

The quick fix is:
# CGI returns the filename and the filehandle in the same variable, gi +ving the # name when treated as a string, and the handle otherwise. Therefore w +e need # to stringify $var explicitly, because Storable can't store a filehan +dle. $db{"1"}{"pic1"} = "$var";
I suggest you leave the comment in place, because it's a pretty unusual circumstance.

Replies are listed 'Best First'.
Re^2: CGI and Storable : explain me this, please.
by lepetitalbert (Abbot) on Apr 27, 2006 at 02:57 UTC

    Hi Monks

    Yes I'm uploading 3 pics.

    this works

    $db{"1"}{"pic1"} = "$var";

    Thanks

    The code is

    for ($i=1; $i < 4; $i++) { $tmp = "pic" . $i; my $filename = $query->param($tmp); $db{$n}{$tmp} = "$filename"; $upload_filehandle = $query->upload($tmp); open UPLOADFILE, ">$upload_dir/$filename"; binmode UPLOADFILE; while ( <$upload_filehandle> ){ print UPLOADFILE; } close UPLOADFILE; } store \%db, $dbfile ;


    Thanks

    Have a nice day

    "There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates
Re^2: CGI and Storable : explain me this, please.
by davidrw (Prior) on Apr 27, 2006 at 04:31 UTC
    i'd guess that scalar $var instead of "$var" would work, too .. dunno (don't think i personally have a preference, though maybe some people would) which is "better" (assuming the former works)

    Update: see below

      Why would being in scalar context stringify a value? A glob in scalar context is still a glob.

        Hmm .. i guess it doesn't. (I tried OP's code w/$db{"1"}{"pic1"} = scalar $var; and it gave the same error ...)

        Well, my line of thought was that $var = join "", split(// , $var); worked because the split's 2nd arg gets treated in scalar context .. So instead, does that mean that split just happens to stringify it's 2nd argument and that's why it worked as OP wanted?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://545935]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found