After getting great help before, I'm back for more. This time I'm working with a similar but different array. I need to do a few things here.... 1) I need to pull any / all lines that start with 'snmp-server host' and stick them into a variable and have this variable formatted as one long line of multiple lines - it'd look similar to this: snmp-server host 10.234.171.46 admin\nsnmp-server host 10.234.171.51 admin frame-relay config snmp\nsnmp-server host 10.234.171.75 admin\n 2) I need to substitute the 4th word in the line(s) starting with 'snmp-server' that is separated by spaces and make it 'Bob' and stick this in a variable, and format it the same as with #1 3) I need to substitute 'snmp-server' with 'no snmp-server' and stick this in a variable I can get #1 & #3 to work if there's just one occurrance in the array, but if there's more than one, then I just get the first one. Any suggestions for any parts would be awesome. thanks, Chris

So, the output from my code could look like: $VAR1 = [ 'snmp-server host 10.234.171.38 JCIPPUBL no cdp advertise-v2 no cdp run !' ]; server host 10.234.171.38 abcd no snmp-server host 10.234.171.38 abcd \n or there can be multiple lines such as this: $VAR1 = [ 'snmp-server host 10.234.171.45 admin snmp-server host 10.234.171.46 admin snmp-server host 10.234.171.51 admin frame-relay config snmp snmp-server host 10.234.171.75 admin snmp-server host 10.234.171.51 publ frame-relay config snmp snmp-server host 10.234.171.54 publ frame-relay config snmp snmp-server host 10.234.171.59 publ !snmp-server host 10.234.171.46 admin snmp-server host 10.234.171.51 admin frame-relay config snmp snmp-server host 10.234.171.75 admin snmp-server host 10.234.171.51 publ frame-relay config snmp snmp-server host 10.234.171.54 publ frame-relay config snmp snmp-server host 10.234.171.59 publ !snmp-server host 10.234.171.51 admin frame-relay config snmp snmp-server host 10.234.171.75 admin snmp-server host 10.234.171.51 publ frame-relay config snmp snmp-server host 10.234.171.54 publ frame-relay config snmp snmp-server host 10.234.171.59 publ !snmp-server host 10.234.171.75 admin snmp-server host 10.234.171.51 publ frame-relay config snmp snmp-server host 10.234.171.54 publ frame-relay config snmp snmp-server host 10.234.171.59 publ !snmp-server host 10.234.171.51 publ frame-relay config snmp snmp-server host 10.234.171.54 publ frame-relay config snmp snmp-server host 10.234.171.59 publ !snmp-server host 10.234.171.54 publ frame-relay config snmp snmp-server host 10.234.171.59 publ !snmp-server host 10.234.171.59 publ !' ]; server host 10.234.171.45 admin no snmp-server host 10.234.171.45 admin \n The code is currently: #!/usr/bin/perl use lib qw(blib lib); #use strict; use warnings; use Getopt::Long; use Pod::Usage; use Data::Dumper; use Opsware::NAS::Client; use Net::Ping; use POSIX qw(strftime); #use TrueControlAPI; my($user,$pass,$host) = ('na_admin', 'na4adm1n', 'localhost'); my $help = 0; my $nas = Opsware::NAS::Client->new(); my $res = $nas->login(-user => $user, -pass => $pass, -host => $host, +-nosession => '0'); print " \n"; #$res = $nas->show_configlet(host => "dev1", start => "snmp-server hos +t", end => "!"); $res = $nas->show_configlet(host => "dev2", start => "snmp-server host +", end => "!"); #$res = $nas->show_deviceinfo(ip => '10.253.74.70'); unless ($res->ok()) { printf STDERR ("*** error: %s\n", $res->error_message()); exit(1); } print (Dumper([$res->result()])); foreach my $var1 ($res->result()) { #my ($image) = $var1 =~ /^SystemImage:\s*([^\n]+)/m my ($snmp) = $var1 =~ /^snmp-\s*([^\n]+)/m or die("No SystemImage\n"); print("$snmp\n"); my ($no_snmp) = 'no snmp-' . $snmp . '\n'; print("$no_snmp\n"); } $nas->logout();

In reply to 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.