in reply to Using IPC::Open3 instead of backtick operator

Perl critic doesn't like the backquote shelling out to the OS. Your solution is way to complex.
#!/usr/bin/perl use warnings; use strict; my @files = glob "*"; print join ("\n", @files),"\n"; open (my $IN, '-|', 'dir') or die "$!"; while (<$IN>) { print; }
Not everything that PerlCritic says is "gospel" - just suggestions.
tested on Windows XP - don't have ls.

Replies are listed 'Best First'.
Re^2: Using IPC::Open3 instead of backtick operator
by ikegami (Patriarch) on Jun 10, 2016 at 16:01 UTC

    This is the equivalent of doing no warnings;. It simply silences the message without addressing the issue (preventing error log from being filled with child's STDERR output). If your goal is simply to circumvent perlcritic, it provides far better ways of doing that.

      My open will capture both the STDERR and STDOUT messages. See below code...

      Main:

      #!/usr/bin/perl use warnings; use strict; open (IN, '-|', 'perl PrintStdoutStdErr.pl') or die "$!"; while (<IN>) { print; } __END__ prints: this went to STDERR this went to STDOUT
      PrintStdoutStdErr.pl
      #!/usr/bin/perl use warnings; use strict; $|=1; print STDOUT "this went to STDOUT\n"; print STDERR "this went to STDERR\n";
      I actually wouldn't worry about Perl critic on an "ls" command.
        My open will capture both the STDERR and STDOUT messages.

        No, it doesn't.

        $ cat main.pl #!/usr/bin/perl use warnings; use strict; open (IN, '-|', 'perl PrintStdoutStdErr.pl') or die "$!"; while (<IN>) { chomp; print "\"$_\"\n"; } $ perl main.pl 1>out 2>err $ cat out "this went to STDOUT" $ cat err this went to STDERR