in reply to Perl System('') question

The advice given by the other folks here is good, but I'd like to suggest using an alternate operator provided by Perl for just this purpose. Backticks are easily misread as single-quotes, so using this improves readability:

my $output = qx#/usr/bin/eject -n#;

See perldoc perlop for more info about 'qx'.


--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^2: Perl System('') question
by spmlingam (Scribe) on Nov 29, 2008 at 04:42 UTC
    Hi, i would like give some more information on this, if the output is more then one line, then use array to get the output.
    my @output = qx(/usr/bin/eject -n);

    If you want to use system function then you can redirect your output to a file and read the file content. it might useful, when you running a program as a daemon.
    The backtick and qx are same, you can use the following option to check your code.
    perl -MO=Deparse <scriptname>.
      What would be the purpose of B::Deparse output? Just use the -c option to check syntax: perl -c file.