Thanks for the info, it's definitely useful. In an effort to simplify my question, here's some background info on what I'm doing, how I'm getting the data, etc. We use an application to manage network devices. It has a series of APIs, some are useful, some not so much. This one gives us the data but it's in an array that seems really difficult to parse / pull data out of. I'm going to focus on just one example, hopefully I'll learn this and be able to apply it to the other cases. I'm working on understanding the code that was suggested, but I think it should work for either case - one result or many results. So, our one case looks like this:
$VAR1 = [ 'snmp-server host 10.234.171.38 abcd snmp-server host 10.234.171.39 abcd snmp-server host 10.234.171.40 abcd !snmp-server host 10.10.10.1 xyz !' ];
What I need is the lines that starts with 'snmp-server host' and I'd need them placed in a string. Start off each instance with the word 'no ' and finish each instance with a return:
no snmp-server host 10.234.171.38 abcd\nno snmp-server host 10.234.171 +.39 abcd\nno snmp-server host 10.234.171.40 abcd\n
When I run the suggested code (I removed the result 2 section for now), I get the following:
$VAR1 = [ 'snmp-server host 208.234.171.38 JCIPPUBL no cdp advertise-v2 no cdp run !' ]; Use of uninitialized value in concatenation (.) or string at replace_e +x10.pl line 34. ---Result 1---
using this code:
my $result_1; for (split /(?<=\n)/, $res->result()) { next unless /^\Qsnmp-server host\E/; $result_1 .= $_; } print "---Result 1---\n$result_1\n\n";
Is it odd that the error (line) is the one printing the value? It's as if the variable result_1 isn't getting any data? I have a feeling that the issue is with the array, as I've had other problems in the past trying to do other things with the data. In the past I used map, I considered split or just a substitution, but I can't seem to get just the data I want - either too much or too little. thanks, Chris
In reply to Re^4: pulling more data from an array
by zonevbkr
in thread pulling more data from an array
by zonevbkr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |