Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ternary expressions with wantarray #26

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 6 additions & 31 deletions lib/IPC/System/Simple.pm
Expand Up @@ -228,15 +228,9 @@ sub capture {
# We'll produce our own warnings on failure to execute.
no warnings 'exec'; ## no critic

if ($wantarray) {
my @results = qx($command);
_process_child_error($?,$command,$valid_returns);
return @results;
}

my $results = qx($command);
my @results = $wantarray ? qx($command) : scalar qx($command);
_process_child_error($?,$command,$valid_returns);
return $results;
return $wantarray ? @results : $results[0];
}

# _win32_capture implements the capture and capurex commands on Win32.
Expand Down Expand Up @@ -326,13 +320,7 @@ sub _win32_capture {

# Read the data from our child...

my (@results, $result);

if ($wantarray) {
@results = <$read_fh>;
} else {
$result = join("",<$read_fh>);
}
my @results = $wantarray ? <$read_fh> : join("", <$read_fh>);

# Tidy up our windows process and we're done!

Expand All @@ -341,7 +329,7 @@ sub _win32_capture {

_check_exit($command,$EXITVAL,$valid_returns);

return $wantarray ? @results : $result;
return $wantarray ? @results : $results[0];

}
}
Expand Down Expand Up @@ -419,23 +407,10 @@ sub capturex {
# Parent process, we don't care about our pid, but we
# do go and read our pipe.

if ($wantarray) {
my @results = <$pipe>;
close($pipe);
_process_child_error($?,$command,$valid_returns);
return @results;
}

# NB: We don't check the return status on close(), since
# on failure it sets $?, which we then inspect for more
# useful information.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I oppose the deletion of the author's inline comment. I am now co-maintainer of this distribution and I found this comment helpful.

my $results = join("",<$pipe>);
my @results = $wantarray ? <$pipe> : join('', <$pipe>);
close($pipe);
_process_child_error($?,$command,$valid_returns);

return $results;

return $wantarray ? @results : $results[0];
}

# Tries really hard to spawn a process under Windows. Returns
Expand Down