Hi,

I thought I had it all figured out. Hash within hashes really made my code 
cleaner until I came up with this code:

While looping, I was creating a key 'webloginpostdata' with value of anonymous 
hash as seen below;

      $all_ap{$_}->{'webloginpostdata'} = {
                                'var:main' => 'menu',
                                'testwebcm' => 'webcm',
                                'login:command/username' => '',
                                'login:command/password' => '',
                                'var:connecting1' => '0'
                        };



Now following the creation above, i'm creating another key 'webadminpostdata' 
which has a value of an anonymous hash again.

      $all_ap{$_}->{'webadminpostdata'} = {
                      'var:main' => 'menu',
                      'var:style' => 'style5',
                
                      'settings/username' => $all_ap{$_}->{'webuser'},
                      'settings/password' => $all_ap{$_}->{'webpass'},
                      'settings/password_confirm' => $all_ap{$_}->{'webpass'},
                      'settings/idle_timeout' => '30'
                };



Then there's two subroutines. The first one ("loginweb") is called. If 
successful, the next one ("changewebpass") is called


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";
        }



"loginweb" sub is really simple:


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 '')?'':$username;
  $$postdata{'login:command/password'} = ($password eq '')?'':$password;
my $res = $ua->request(POST $url, $postdata);
if ($res->content =~ /Basic\s+Home\s+Menu/){
print "     SUCCESS!!!\n";
return 'success';
}else{
next;
}

}



Finally, here's the "changewebpass"


sub changewebpass{

my $url = shift;
my $postdata = shift;
my $res = $ua->request(POST $url, $postdata);

if ($res->is_success){
 return 'success';
}else{
 return 'failed';
 }

}



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 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:

my %webloginpostdata = (...);
my %webadminpostdata = (...);

Then pass their references to the sub routines: ie,
loginweb(\%webloginpostdata)


I didn't have any troubles doing so.














      

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to