ybiC has asked for the wisdom of the Perl Monks concerning the following question:
Here's my question - can repetition of lines 16-19 be re-written more concisely?
cheers,
Don
striving for Perl Adept
Sample Input (./count.in)1 #!/usr/bin/perl -w 2 3 use strict; 4 5 my $infile = './count.in'; 6 my $vlan = "0"; 7 my $up = "0"; 8 my $down = "0"; 9 my $shut = "0"; 10 11 { 12 local $/ = undef; 13 open(IN, "<$infile") or die "Cannot open $infile: $!"; 14 my $filestring = <IN>; 15 close IN or die "Cannot close $infile: $!"; 16 while ($filestring =~ /VLAN/g) { $vlan++ } 17 while ($filestring =~ /ifOperStatus.*up\(1\)/g) { $up++ } 18 while ($filestring =~ /ifOperStatus.*down\(2\)/g) { $down++ } 19 while ($filestring =~ /ifAdminStatus.*down\(2\)/g) { $shut++ } 20 } 21 22 my $live = ($up - $vlan); 23 my $total = ($live + $down); 24 25 print "$vlan VLAN(s)\n"; 26 print "$total physical ports\n"; 27 print "$live active port(s)\n"; 28 print "$down inactive port(s)\n"; 29 print "$shut disabled port(s)\n";
interfaces.ifTable.ifEntry.ifAdminStatus.1 = up(1) interfaces.ifTable.ifEntry.ifAdminStatus.2 = up(1) interfaces.ifTable.ifEntry.ifAdminStatus.3 = up(1) interfaces.ifTable.ifEntry.ifAdminStatus.4 = up(1) interfaces.ifTable.ifEntry.ifAdminStatus.5 = down(2) interfaces.ifTable.ifEntry.ifOperStatus.1 = up(1) interfaces.ifTable.ifEntry.ifOperStatus.2 = up(1) interfaces.ifTable.ifEntry.ifOperStatus.3 = up(1) interfaces.ifTable.ifEntry.ifOperStatus.4 = down(2) interfaces.ifTable.ifEntry.ifOperStatus.5 = down(2) interfaces.ifTable.ifEntry.ifDescr.1 = VLAN1 interfaces.ifTable.ifEntry.ifDescr.2 = FastEthernet0/1 interfaces.ifTable.ifEntry.ifDescr.3 = FastEthernet0/2 interfaces.ifTable.ifEntry.ifDescr.4 = FastEthernet0/3 interfaces.ifTable.ifEntry.ifDescr.5 = FastEthernet0/4
|
|---|