diff options
author | Jacob Pipkin <j@dawnrazor.net> | 2012-06-05 12:44:48 -0500 |
---|---|---|
committer | Jacob Pipkin <j@dawnrazor.net> | 2012-06-05 12:44:48 -0500 |
commit | a158c22df50796bbf02d876d6197635a1899aba6 (patch) | |
tree | 22714fae8f37adafe1be78f8488b523edbbdcb1e /sbofind | |
parent | ae9bb71900fe625562c124debcf4f7b316a1bb3a (diff) | |
download | sbotools2-a158c22df50796bbf02d876d6197635a1899aba6.tar.xz |
factored out "open my $fh, $op, $file" and made it robust in one fell swoop
Diffstat (limited to 'sbofind')
-rwxr-xr-x | sbofind | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -51,8 +51,8 @@ slackbuilds_or_fetch (); my (@findings, $name); my $found = 'FALSE'; my $regex = qr/NAME:\s.*\Q$search\E.*/i; -open my $sb_txt, '<', "$config{SBO_HOME}/SLACKBUILDS.TXT"; -FIRST: while (my $line = <$sb_txt>) { +my $fh = open_read ("$config{SBO_HOME}/SLACKBUILDS.TXT"); +FIRST: while (my $line = <$fh>) { unless ($found eq 'TRUE') { if ($line =~ $regex) { $found = 'TRUE'; @@ -74,8 +74,7 @@ FIRST: while (my $line = <$sb_txt>) { sub get_file_contents { script_error ('get_file_contents requires an argument') unless exists $_[0]; script_error ('get_file_contents argument is not a file') unless -f $_[0]; - my $file = shift; - open my $fh, '<', $file; + my $fh = open_read (shift); my $contents = do {local $/; <$fh>}; $contents =~ s/\n/\n /g; $contents =~ s/ $//g; |