On 12/8/09 Tue Dec 8, 2009 5:41 PM, "Noah" <[email protected]>
scribbled:
>
> Hi there List people,
>
> I am hoping to send a hash and a scalar to a subroutine but the variable
> is not completely being sent. Below is the error message below is
> showing something is not getting passed that well to the subroutine.
> Looks like %login is empty.
If %login were "empty", then the line $login{$hostname}->send("exit"); would
result in a different error: Can't call method "send" on an undefined value.
It is more likely that one or all of $position, $error, $matched, $before,
or $after are assigned an undefined value by the call to
$login{$hostname}->send("exit"), perhaps because of an error. Does that
method have any error checking or error return value?
>
> $ret{$hostnames[0]} = $login{$hostnames[0]}->send_cmd("edit");
> $ret{$hostnames[1]} = $login{$hostnames[1]}->send_cmd("edit");
>
> if ($ret{$hostnames[0]} =~ /^blah/m) {
> exiting ($hostnames[0], %login);
> }
>
> if ($ret{$hostnames[1]} =~ /^blah/m) {
> exiting ($hostnames[1], %login);
> }
>
>
> sub exiting {
> my ($hostname, %login) = @_;
> my ($ret);
> print "login: $login $hostname\n";
> my ( $position, $error, $matched, $before, $after ) =
> $login{$hostname} -> send("exit\n");
> print "position: $position, $error, $matched, $before, $after \n";
> exit 0;
You do realize that the following lines will not be executed, don't you?
> if ($ret{$hostname} =~ /^blah/m) {
> $login{$hostname}->send_cmd("yes")
> }
> $ret{$hostname} = $login{$hostname}->send_cmd("exit");
> }
Use the Data::Dumper module to inspect the contents of %login:
use Data::Dumper;
...
print Dumper(\%login);
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/