You are getting the uninitialized value warning because $result_1 is undef when fed into print. The real issue is that you are never executing the line $result_1 .= $_;. There are two possibilities I can think of for why this might happen: $res->result() might not return a string as I've assumed or $res->result() is stateful and does not return the same thing on subsequent invocations. I do not have access to documentation on Opsware::NAS::Client, so I can only guess. Two tests you may consider would be running the output through a simple print to make sure you are getting what you expect (print for split /(?<=\n)/, $res->result();) and storing the value in a scalar and feeding that into Data::Dumper (print Dumper $_ = $res->result()).

I copied your Data::Dumper output and filtering loop in to the following code:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $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 !' ]; my $result_1; for (split /(?<=\n)/, $VAR1->[0]) { next unless /^\Qsnmp-server host\E/; $result_1 .= $_; } print "---Result 1---\n$result_1\n\n";

which gives me the result

---Result 1--- snmp-server host 10.234.171.38 abcd snmp-server host 10.234.171.39 abcd snmp-server host 10.234.171.40 abcd

Does this match your expectation?


In reply to Re^5: pulling more data from an array by kennethk
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.