Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
..."...become a better Perl programmer...update the script to pass the perlcritic test..."

I fear you won't become a better Perl programmer if you use perlcritic. The opposite might happen and this would be annoying. From the linked node by our beloved deputy of the leader BUK:

..."Fully 95% of Perl::Critic's (and by implication PBP) justifictions are as puerile as banning ball games from school playgrounds because participants might skin their knees. Making their own mistakes and learning from them is how kids learn. Banning every construct and idiom, that might under some obscure circumstances cause the occasional program to fail, is like trying to wrap your kids in cotton wool. Overindulgent, counter-productive and ultimately futile..."

Below some code that i wrote a while ago for learning purposes and demonstration - how to capture everything from a compound external command:

#!/usr/bin/env perl use strict; use warnings; use IPC::Run qw( run harness ); use Try::Tiny; use Carp; my $file = shift || $0; my @cat = ( "cat", $file ); my @wc = qw( wc -l ); my ( $error, $result ); my @command = ( \@cat, '|', \@wc, '1>', \$result, '2>', \$error ); my $harness = harness @command; try { run $harness; croak $error if $harness->full_result; } catch { print qq(Error: $_); }; chomp $result; printf( "%s:\t%s\n", "result", $result ); printf( "%s:\t%s\n", "cat", $harness->full_result(0) ); printf( "%s:\t%s\n", "wc", $harness->full_result(1) ); __END__

Some mentioned already that IPC::Run might be the better tool.

The code fails with perlcritic, despite it is IMHO well formatted, easy to read, easy to understand and therefore easy to maintain. And it does what it should do.

karls-mac-mini:Desktop karl$ perlcritic -1 ipc.pl Code is not tidy at line 1, column 1. See page 33 of PBP. (Severity: + 1) No package-scoped "$VERSION" variable found at line 1, column 1. See +page 404 of PBP. (Severity: 2) Magic punctuation variable $0 used at line 9, column 21. See page 79 +of PBP. (Severity: 2) Useless interpolation of literal string at line 11, column 13. See pa +ge 51 of PBP. (Severity: 1) Quotes used with a noisy string at line 17, column 24. See page 53 of + PBP. (Severity: 2) Return value of flagged function ignored - print at line 26, column 5. + See pages 208,278 of PBP. (Severity: 1) Useless interpolation of literal string at line 31, column 21. See pa +ge 51 of PBP. (Severity: 1) Builtin function called with parentheses at line 33, column 1. See pa +ge 13 of PBP. (Severity: 1) Useless interpolation of literal string at line 33, column 22. See pa +ge 51 of PBP. (Severity: 1) Builtin function called with parentheses at line 35, column 1. See pa +ge 13 of PBP. (Severity: 1) Useless interpolation of literal string at line 35, column 22. See pa +ge 51 of PBP. (Severity: 1)

OK, the command is idiotic, but perlcritic doesn't complain about that it is idiotic.

No Perl shari'ah, thank's.

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»


In reply to Re: Using IPC::Open3 instead of backtick operator by karlgoethebier
in thread Using IPC::Open3 instead of backtick operator by rcrews

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2021-11-28 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?