diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-02-03 11:35:08 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-02-03 11:40:19 -0800 |
commit | 381cd4352c00663ac01210a499a4c8c499e0de36 (patch) | |
tree | 5c89c1551d5cb564bee93da5eafaf08ab17932d6 /scripts/vyatta-load-config.pl | |
parent | cc25ba067b79b91c92e0f67026e04a9b295dae76 (diff) | |
download | vyatta-cfg-381cd4352c00663ac01210a499a4c8c499e0de36.tar.gz vyatta-cfg-381cd4352c00663ac01210a499a4c8c499e0de36.zip |
Replace bare file handle with variable
PBP recommends using local variable rather than global file handle.
Diffstat (limited to 'scripts/vyatta-load-config.pl')
-rwxr-xr-x | scripts/vyatta-load-config.pl | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index a942019..6036685 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -70,11 +70,10 @@ if ( $mode eq 'local' and !( $load_file =~ /^\// ) ) { $load_file = "$bootpath/$load_file"; } +my $cfg; if ( $mode eq 'local' ) { - if ( !open( CFG, "<$load_file" ) ) { - print "Cannot open configuration file $load_file\n"; - exit 1; - } + die "Cannot open configuration file $load_file: $!\n" + unless open( $cfg, '<', $load_file); } elsif ( $mode eq 'url' ) { if ( !-f '/usr/bin/curl' ) { @@ -110,16 +109,15 @@ elsif ( $mode eq 'url' ) { print "Can not open remote configuration file $load_file\n"; exit 1; } - if ( !open( CFG, "<$url_tmp_file" ) ) { - print "Cannot open configuration file $load_file\n"; - exit 1; - } + die "Cannot open configuration file $load_file: $!\n" + unless open( $cfg, '<', $url_tmp_file); + $load_file = $url_tmp_file; } my $xorp_cfg = 0; my $valid_cfg = 0; -while (<CFG>) { +while (<$cfg>) { if (/\/\*XORP Configuration File, v1.0\*\//) { $xorp_cfg = 1; last; @@ -142,7 +140,7 @@ if ( $xorp_cfg or !$valid_cfg ) { exit 1; } } -close CFG; +close $cfg # log it openlog( $0, "", LOG_USER ); |