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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.