in reply to Re^2: pulling more data from an array
in thread pulling more data from an array
you've gotten rid of the parts that I need to produce the data. Was this to show how to handle the data once I get it?
I did that because I don't have all those modules installed, so I couldn't execute your script as posted. However, as you posted the result of Data::Dumper, I used that to replicate your internal state as the crux of your question was how to manipulate the data. I try and do my best to test code before I post, since posting broken code yields more confusion than assistance. I would expect the following (obviously untested) code to replicate my output with your data collection technique:
#!/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()]), "\n\n"); my $result_1; for (split /(?<=\n)/, $res->result()) { next unless /^\Qsnmp-server host\E/; $result_1 .= $_; } print "---Result 1---\n$result_1\n\n"; my $result_2; for (split /(?<=\n)/, $res->result()) { next unless /^\Qsnmp-server\E/; s/^((?:\S+\s+){3})\S+/${1}Bob/; $result_2 .= $_; } print "---Result 2---\n$result_2\n\n";
Regarding my algorithm for obtaining the first result, it can be broken down as follows:
Result 2 functions similarly to result 1 with the addition of a substitution. s/^((?:\S+\s+){3})\S+/${1}Bob/; can be broken down as follows:
I hope this is clear. See perlre or perlretut for more info on building regular expressions. For the future, try to include sample input and expected output, wrapped in code tags, so we have something test our code against. Good luck.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: pulling more data from an array
by zonevbkr (Initiate) on Aug 05, 2010 at 19:26 UTC | |
by kennethk (Abbot) on Aug 05, 2010 at 20:17 UTC | |
by zonevbkr (Initiate) on Aug 05, 2010 at 22:33 UTC | |
by kennethk (Abbot) on Aug 05, 2010 at 22:39 UTC |