I have written a function that executes a command, parses the output based on the regex, and returns two values, status and ip. Function call returns both the values as expected. Instead of returning a scalar, I want to return hash ref. Can some one tell me how to do return a hash ref for the below function?
sub status {
my ($self,$int) = @_;
my $status = 0;
my $ip = 0;
my $cmd = 'cisco ios command ' . $interface;
my $out = $self->{sshObj}->exec($cmd);
foreach my $line ( $out ) {
if ( $line =~ m/Session\s+status:\s+(.*)/ ) {
$status = $1;
}
if ( $line =~ /(\d+.\d+.\d+.\d+)/ ) {
$ip = $1;
}
}
return ($status,$ip);
}
function call :
my ($status, $ip) =
$self->{'$tunnel_obj'}->status($self->{'outer_t_1'});
INFO ("status : $status");
INFO ("ip : $ip");
Output :
status : UP
ip : 172.10.78.33