From b70c02f69ea5abf32e0ebe4781e6cd396a4a1dd4 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 29 Feb 2008 12:15:52 -0800 Subject: use exec rather than open with path This avoids a number of future problems with bareword filehandles. See Perl Best Practices (Chapter 10) --- scripts/firewall/vyatta-show-firewall.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'scripts/firewall/vyatta-show-firewall.pl') diff --git a/scripts/firewall/vyatta-show-firewall.pl b/scripts/firewall/vyatta-show-firewall.pl index 4995a09..78e6b68 100755 --- a/scripts/firewall/vyatta-show-firewall.pl +++ b/scripts/firewall/vyatta-show-firewall.pl @@ -26,15 +26,17 @@ sub show_chain { my $chain = shift; my $fh = shift; - open(STATS, "/sbin/iptables -L $chain -vn |") or exit 1; + open my $iptables, "-|" + or exec "sudo", "/sbin/iptables", "-L", $chain, "-vn" + or exit 1; my @stats = (); - while () { + while (<$iptables>) { if (!/^\s*(\d+[KMG]?)\s+(\d+[KMG]?)\s/) { next; } push @stats, ($1, $2); } - close STATS; + close $iptables; print $fh "\n"; my $config = new VyattaConfig; -- cgit v1.2.3