Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: A simple backticks question

by no_slogan (Deacon)
on Mar 17, 2014 at 16:18 UTC ( [id://1078619]=note: print w/replies, xml ) Need Help??


in reply to A simple backticks question

Technically, the backtick operator returns a list, which is subtly different from an array. (You can't use it as the first argument to push, for example.) Arrays are automatically converted to lists when evaluated in list context.

Replies are listed 'Best First'.
Re^2: A simple backticks question
by LanX (Saint) on Mar 17, 2014 at 16:32 UTC
    Not fully correct, the backticks are context sensitive, in scalar context `ls -l` will return a concat of all lines. (a list array¹ in scalar context returns the number of lines)

    backtick/qx in perlop

    In scalar context, it comes back as a single (potentially multi- line) string, or undef if the command failed. In list context, returns a list of lines (however you’ve defined lines with $/ or $INPUT_RECORD_SEPARATOR), or an empty list if the command failed.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    updates

    ¹) corrected, thanks to no_slogan. It very much depends on what the command within backticks returns.

      Thanks for the correction, but again, not exactly correct. An array in scalar context evaluates to its number of elements. There is no such thing as a list in scalar context.
        well with exception of the empty list! ;-)

        DB<124> $x = () => undef

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1078619]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found