CA_API has asked for the wisdom of the Perl Monks concerning the following question:
Hello all. I am new here and hope this is a landing spot for junior folks like me who are in need of suggestions. If I'm in the wrong spot, quite sorry and thank you for your time. If so, perfect as I am having some trouble working with an array element. What is going on is we use an API that will let us connect to a Cisco device (router / switch) and issue a specified command and we get back the results. I use a push to populate the array. This works pretty well. Here's an example of the output of the array:
$VAR1 = [ [ 'show users | include idle 00:00:00', '*194 vty 0 spec idle 00:00:00 10.2 +34.171.75' ] ];
What I am after is the IP address at the end. In the case of the example, 10.234.171.75 Is there a way to work backwards to just get the IP? I'm finding ways to do basically this but for an element. In my case, I just have the one element. I've included the main code from my script, though don't think this is useful.
## ## Prepare for array to hold data from cmd ## This will hold the line sent (unfortunately - future work - fi +nd way to not capture this) ## This will hold the line returned, there should just be one lin +e. ## I am interested in IP, this IP could vary ## my @res = (); ## ## Note that the 'cmd()' method will return the results ## that were observed on the target device, following the ## given command. push @res, [$con->cmd("show users | include idle +00:00:00")]; ## print Dumper \@res;
I'm trying to get a foreach loop to work thru the array a space at a time, but this seems poor. Regards, Brian
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: working backwards in an array element?
by talexb (Chancellor) on Aug 27, 2010 at 17:03 UTC | |
by CA_API (Initiate) on Aug 28, 2010 at 00:39 UTC | |
|
Re: working backwards in an array element?
by Utilitarian (Vicar) on Aug 27, 2010 at 17:07 UTC | |
|
Re: working backwards in an array element?
by umasuresh (Hermit) on Aug 27, 2010 at 20:53 UTC | |
by talexb (Chancellor) on Aug 28, 2010 at 16:41 UTC | |
|
Re: working backwards in an array element?
by pemungkah (Priest) on Aug 29, 2010 at 00:36 UTC |