I am executing a command it is returning me something like this
name ip port
------------------------------------
http-listener-1 * 6712
http-listener-2 * 8709
I have a subroutine getListenerName($porttobeChecked)
This subroutine returns me the name of the listener if i pass a port.
Eg:If $porttobechecked=6712 I want to return an array a[0]=TRUE and a[1]=http-listener-1(listener name)
If port to be checked is 4516..I want to return an array a[0]=FALSE and a[1]=null
How can i parse this output.Any help appreciated?
#! /usr/bin/perl -w
use strict;
sub getListenerName {
my $port = shift;
my @a = ();
open F, "< file";
while (<F>) {
chomp;
if (/([^ ]*).+?$port/) {
$a[0] = "TRUE";
$a[1] = $1;
last;
}
else {
$a[0] = "FALSE";
$a[1] = "null";
}
}
close F;
return @a;
}
my @x = &getListenerName (6712);
print "@x\n";
1 Like
Thanks
TI am getting this output as array @outputarray also output is dynamic the name and port can change .How can i parse this where
outputarray[0]=name ip port
outputarray[0]=------------------------------------
outputarray[0]=http-listener-1 * 6712
I've assumed that the below data is stored in a file.
name ip port
------------------------------------
http-listener-1 * 6712
http-listener-2 * 8709
Is it not?
Its coming as array @outputarray
Pardon me for mistake I am beginner in perl
outputarray[0]=name ip port
outputarray[1]=------------------------------------
outputarray[2]=http-listener-1 * 6712
outputarray[3]=http-listener-2 * 4743
I can also get the output array as like below if above is difficult to parse
outputarray[0]=http-listener-1 * 6712
outputarray[1]=http-listener-2 * 4743