in reply to Re: Interacting with the shell ( backticks, system(), open -| )
in thread Interacting with the shell ( backticks, system(), open -| )

Dave, Here is the script I use when using system():
#! /usr/bin/perl use strict; use warnings; my @files = system "find . -ls"; foreach my $file (@files) { chomp $file; print "$file\n"; }
And it outputs the following (I deleted the userid column):
1105134059 2 drwxr-xr-x 3 .... users 2048 Feb 5 09:40 . 1105135378 1 -rw-r--r-- 1 .... users 506 Feb 3 10:54 ./t +est.pl 1105135090 1 -rw-r--r-- 1 .... users 93 Jan 24 15:41 ./c +alendar.pl 0
Notice the trailing 0? If I replace my @files = system "find . -ls"; with my @files = `find . -ls`;, I get the same output, except the trailing 0 is missing.

I understand why system() prints out the trailing 0 (it's the exit status of find()), but why is it also outputting everything find() outputs? I thought it should only return the exit status.

Replies are listed 'Best First'.
Re^3: Interacting with the shell ( backticks, system(), open -| )
by choroba (Cardinal) on Feb 05, 2014 at 15:01 UTC
    find itself outputs the lines. System does not return them, it only returns the exit status. You can verify none of the lines is printed via print by wrapping the values in parentheses:
    print "($file)\n";

    The zero will be the only parenthesized string.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: Interacting with the shell ( backticks, system(), open -| )
by Corion (Patriarch) on Feb 05, 2014 at 15:02 UTC

    Have you compared system against qx? They do different things. Most importantly, system does not return the output of the child.