diff options
author | Robert Rothenberg <rrwo@cpan.org> | 2020-03-29 13:09:46 +0100 |
---|---|---|
committer | Robert Rothenberg <rrwo@cpan.org> | 2020-03-29 13:09:46 +0100 |
commit | 99f326be09ab345eed3d9701ea62d7c40c41aa6c (patch) | |
tree | 8def650faad1f7234a32da0c73aa972ba16e7b1c | |
parent | 2779b02f8f38a442b729426e7e32d5368b350d45 (diff) |
Change uptime to use backticks instead of piped open
-rw-r--r-- | Changes | 2 | ||||
-rw-r--r-- | lib/Sys/CpuLoad.pm | 14 |
2 files changed, 6 insertions, 10 deletions
@@ -4,6 +4,8 @@ Revision history for Perl extension {{$dist->name}}: [Enhancements] - Support getloadavg for DragonFly BSD. + - Change uptime to use backticks instead of piped open. + [Bug Fixes] - uptime immediately returns undef if path to `uptime` cannot be found. diff --git a/lib/Sys/CpuLoad.pm b/lib/Sys/CpuLoad.pm index 8135150..6c24a85 100644 --- a/lib/Sys/CpuLoad.pm +++ b/lib/Sys/CpuLoad.pm @@ -106,18 +106,12 @@ sub uptime { $uptime ||= which("uptime") or return undef; ## no critic (ProhibitExplicitReturnUndef) - my $fh = IO::File->new("${uptime}|"); - if ( defined $fh ) { - my $line = <$fh>; - $fh->close(); - if ( $line =~ - /(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*$/ ) - { - return ( $1, $2, $3 ); - } + my $line = `$uptime`; + if ( $line =~ /(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*$/ ) + { + return ( $1, $2, $3 ); } return undef; ## no critic (ProhibitExplicitReturnUndef) - } sub BEGIN { |