From eaf4e68ae42b1e4e5c4f5ca0ea944c0ab383157b Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 4 Feb 2009 10:15:50 -0800 Subject: Vyatta::Config::returnValue - change to three argument open Using three argument open is safer against global handle clash, and accidental scripting. --- lib/Vyatta/Config.pm | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index 9e57448..77fb440 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -206,19 +206,16 @@ sub returnValue { $node =~ s/\//%2F/g; $node =~ s/\s+/\//g; - if ( -f "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node/node.val" ) { - open FILE, "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node/node.val" || return undef; - read FILE, $tmp, 16384; - close FILE; + return unless + open my $file, '<', + "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node/node.val"; - $tmp =~ s/\n$//; - return $tmp; - } - else { - return undef; - } -} + read $file, $tmp, 16384; + close $file; + $tmp =~ s/\n$//; + return $tmp; +} ## returnOrigValue("node") # returns the original value of "node" (i.e., before the current change; i.e., @@ -231,16 +228,14 @@ sub returnOrigValue { $node =~ s/\//%2F/g; $node =~ s/\s+/\//g; my $filepath = "$self->{_active_dir_base}$self->{_current_dir_level}/$node"; - if ( -f "$filepath/node.val") { - open FILE, "$filepath/node.val" || return undef; - read FILE, $tmp, 16384; - close FILE; - $tmp =~ s/\n$//; - return $tmp; - } else { - return undef; - } + return unless open my $file, '<', "$filepath/node.val"; + + read $file, $tmp, 16384; + close $file; + + $tmp =~ s/\n$//; + return $tmp; } ## returnValues("node") -- cgit v1.2.3