I snmp a list of devices, pull back 2 snmp variables and parse through to get the following :
10.200.129.131 C3500XL 12.0(5)WC8 milwaukee-2
10.200.129.6 C3550 12.1(13)EA1c atlanta
10.200.13.3 C3550 12.1(13)EA1a nbglendale
10.200.139.4 C3500XL 12.0(5)WC10 maryland1
The perl entries to parse through the results are shown below.
The problem that I am having is; I do not want to dump these results to a file. I would like to put them into a single array later on in the script (which I havent written yet) I may need pieces of this list to perform other functions on the device.
How the heck do I get each defined var into an array ?
Ive tried but if the var isnt defined... it chokes.
@array = ($var1, $var2, $var3);
Me book says - 2 ways to create arrays. type in using list (x, y, z) or feed in using scalars ... Im stumped ...
foreach $inv (@INV) {
chomp $inv;
#
if ($inv =~ /^IOS/) {
@ver1 = split(/ /,$inv);
$ver1[6] =~ s/,//g;
print "$ver1[2]\t$ver1[6]\t";
}
elsif ($inv =~ /sysName/) {
$inv =~ s/.*STRING: //g;
$inv =~ s/.net.na.abnamro.com//g;
print "$inv\n";
$inv1 = $inv
}
elsif ($inv =~ /Cisco IOS Software/) {
@ver2 = split(/ /,$inv);
$ver2[10] =~ s/,//g;
print "$ver2[6]\t$ver2[10]\t";
}
elsif ($inv =~ /WS\-/) {
@ver3 = split(/WS/,$inv);
$ver3[1] =~ s/-//g;
print "$ver3[1]\t";
}
elsif ($inv =~ /Catalyst Operating System/) {
@ver4 = split(/ /,$inv);
print "$ver4[6]\t";
}#end elsif
#
}#end for
Thanks alot !!!