From a158c22df50796bbf02d876d6197635a1899aba6 Mon Sep 17 00:00:00 2001 From: Jacob Pipkin Date: Tue, 5 Jun 2012 12:44:48 -0500 Subject: factored out "open my $fh, $op, $file" and made it robust in one fell swoop --- sbofind | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sbofind') diff --git a/sbofind b/sbofind index 5095e5e..999801a 100755 --- a/sbofind +++ b/sbofind @@ -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; -- cgit v1.2.3