Also note the material you posted is far more complicated than it need be - you are using 7 different modules and have strict commented out when you really just need know how to process your sample input. You also can include multiple instances of <code> tags in one post, and this can really aid in clarity.
I don't understand what you mean by case 3 (an example is worth 1,000 words) but everything else you ask can be done in a fairly straight-forward fashion using regular expressions and Loop Control. I've crafted up some simple treatments, where I've assumed $res->result() returns a scalar string as indicated by your Data::Dumper output. If anything is unclear, I'll be happy to clarify:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data = do{local $/; <DATA>}; print Dumper([$data]), "\n\n"; my $result_1; for (split /(?<=\n)/, $data) { next unless /^\Qsnmp-server host\E/; $result_1 .= $_; } print "---Result 1---\n$result_1\n\n"; my $result_2; for (split /(?<=\n)/, $data) { next unless /^\Qsnmp-server\E/; s/^((?:\S+\s+){3})\S+/${1}Bob/; $result_2 .= $_; } print "---Result 2---\n$result_2\n\n"; __DATA__ 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 !
In reply to Re: pulling more data from an array
by kennethk
in thread pulling more data from an array
by zonevbkr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |