Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

how to put values into $$rhash_params{'import_file'}->filename?

by MelaOS (Beadle)
on Sep 17, 2008 at 08:59 UTC ( [id://711932]=perlquestion: print w/replies, xml ) Need Help??

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

hi there, i'm using apache as our web server and it's in unix environment, seriously i sux at both of these. and i have these two variables which i would like to set their values manually.
$$rhash_params{'import_file'}->fh; $$rhash_params{'import_file'}->filename
the pointer to hash is basically retrieving values fomr the apache upload parameter. so from the code i can see that we retrieve the values using apache
#------------------------------------------------------ # Handle all POST, GET, multipart, and upload requests #------------------------------------------------------ my $r = Apache->request(); my $apr = Apache::Request->new($r); my @keys = $apr->param; foreach (@keys) { my @value = $apr->param($_); next unless scalar @value; if (@value>1){ $params{$_} = \@value; } else { $params{$_} = $value[0]; } } my $upload = $apr->upload; if ($upload) { $params{'import_file'} = $upload; }

but manually i have no idea how to populate values into these two values. i've read somewhere it's some sort of apache table or something, it got too technical so i couldn't continue reading it.
yea i know i'm an idiot, so please help me out :)
thanks
~perlnoob

Replies are listed 'Best First'.
Re: how to put values into $$rhash_params{'import_file'}->filename?
by jonadab (Parson) on Sep 17, 2008 at 10:32 UTC

    I'm not 100% sure what you're asking, at least partly because I've never used the Apache::Request module, but if all you want to do is store values in a hash, you can do that with a straightforward normal assignment operation. The fact that the hash is nested inside another data structure doesn't matter:

    my %foo; my $bar = { key1 => "value 1", }; $foo{key2} = "value 2"; $$bar{key3} = "value 3"; $$bar{key4} = { key5 => "value 5", }; $$bar{key4}->{key6} = "value 6"; $$bar{key4}{key7} = "value 7"; # simpler syntax use Data::Dumper; print Dumper( \%foo, \$bar );
    If there's something different going on that I've missed (e.g., a tied hash), or something more you wanted to know, you might try to clarify your question. As it stands now, this is the only answer I could come up with.
    -- 
    We're working on a six-year set of freely redistributable Vacation Bible School materials.
      hi man,
      actually let me try to explain what i'm doing here:
      #------------------------------------------------------ # Handle all POST, GET, multipart, and upload requests #------------------------------------------------------ my $r = Apache->request(); my $apr = Apache::Request->new($r); my @keys = $apr->param; foreach (@keys) { my @value = $apr->param($_); next unless scalar @value; if (@value>1){ $params{$_} = \@value; } else { $params{$_} = $value[0]; } } my $upload = $apr->upload; if ($upload) { $params{'import_file'} = $upload; }
      this is the default method for uploading files using modcgi page via apache. but my problem is that i'm trying to upload files directly from the server bypassing this uploading modcgi page.
      unfortunately, most of the functions in my company uses hash{param} method to store parameters, so the file handler and the file name is actually kept using this method. so i need to find a way to put in the file name and the file handle parameter to the $$rhash_params variable so i can minimize changes to the functions that i'm using.
      thanks for your answer, i try your method and using the ->filename i got this error:
      error Can't modify non-lvalue subroutine call at /script.pm line 1467.\n
      and using the {}{} method i got this error msg:
      error Not a HASH reference at /media/www/vprimary/script.pm line 1468.\n
      from using data dumper this is what i've got:
      $VAR1 = { 'file_handler' => bless( \*Apache::Upload::_GEN_2410, 'Apach +e::Upload' ), 'import_file' => bless( do{\(my $o = 447703164)}, 'Apache::U +pload' ), };
      any idea how do i put values into the import file or file handler?
      thanks & sorry for the belated reply.
      ~perlnoobian

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found