markus_ben has asked for the wisdom of the Perl Monks concerning the following question:
Now following the creation above, i'm creating another key 'webadminpostdata' which has a value of an anonymous hash again.$all_ap{$_}->{'webloginpostdata'} = { 'var:main' => 'menu', 'testwebcm' => 'webcm', 'login:command/username' => '', 'login:command/password' => '', 'var:connecting1' => '0' };
Then there's two subroutines. The first one ("loginweb") is called. If successful, the next one ("changewebpass") is called$all_ap{$_}->{'webadminpostdata'} = { 'var:main' => 'menu', 'var:style' => 'style5', 'settings/username' => $all_ap{$_}->{'webuser'}, 'settings/password' => $all_ap{$_}->{'webpass'}, 'settings/password_confirm' => $all_ap{$_}->{'we +bpass'}, 'settings/idle_timeout' => '30' };
"loginweb" sub is really simple:my $login_status = loginweb($all_ap{$_}->{'webloginurl'}, $all_ap{$_}- +>{'webloginpostdata'}); if ($login_status eq 'success'){ ## Call next subroutine my $setpassword = changewebpass($all_ap{$_}->{'webadminurl'}, $all_ap{ +$_}->{'webadminpostdata'}); if ($setpassword ne 'success'){ print "Can\'t change password\n"; }else{ print "New login created:\n\t username: $all_ap{$_}->{'webuser'} + \n\t password: $all_ap{$_}->{'webpass'}\n"; }
Finally, here's the "changewebpass"sub loginweb{ my $url = shift; my $postdata = shift; my $username; my $password; open PASSLIST, "appasswd.txt" or die $!; while (<PASSLIST>){ $username = (split / === /, $_)[0]; $password = (split / === /, $_)[1]; chomp ($username, $password); print "\nTrying username: \'$username\' password: \'$password\'"; $$postdata{'login:command/username'} = ($username eq '')?'':$usernam +e; $$postdata{'login:command/password'} = ($password eq '')?'':$passwor +d; my $res = $ua->request(POST $url, $postdata); if ($res->content =~ /Basic\s+Home\s+Menu/){ print " SUCCESS!!!\n"; return 'success'; }else{ next; } }
When I run my program, I get an error: "Need a field name at (eval 11) line 1" That's all. No mention of line number, or whatever. Perhaps that is because the error was not a syntax error but a perl module (HTTP::Request...etc.) error. Further investigation showed that after calling loginweb, my $all_ap($_}->{'webadminpostdata'} gets emptied. calling 'changewebaccess', nothing is being assigned to $postdata. That is why i'm getting that error. Any idea where to look into?? In my code before, I only had to declare the actual hashes:sub changewebpass{ my $url = shift; my $postdata = shift; my $res = $ua->request(POST $url, $postdata); if ($res->is_success){ return 'success'; }else{ return 'failed'; } }
I didn't have any troubles doing so. Please enlighten me.my %webloginpostdata = (...); my %webadminpostdata = (...); </code ## Then pass their references to the sub routines: ie, <code> loginweb(\%webloginpostdata)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: passing hash reference to HTTP::Request::Common destroys my other hash
by kennethk (Abbot) on May 21, 2009 at 14:32 UTC | |
by markus_ben (Initiate) on May 21, 2009 at 20:03 UTC | |
|
Re: passing hash reference to HTTP::Request::Common destroys my other hash
by Anonymous Monk on May 21, 2009 at 13:12 UTC | |
by markus_ben (Initiate) on May 21, 2009 at 13:20 UTC |