Depending on the context we get either a scalar or an array. Ok so far.
But in the following:
print reverse <STDIN>;
Why do I get a list context? I mean reverse according to doc is either a list or a scalar context. So is print.
Prints a string or a list of strings. Returns true if successful.
So is STDIN
. So why does STDIN
here retrieve lines until EOF and not just collect the first line?
You seem to be conflating two independent things:
The operands of reverse
are always evaluated in list context.
reverse LIST
So <STDIN>
will be evaluated in list context.
Like all operators that can return something other than a scalar, reverse
behaves differently in scalar context and in list context.
The operands of print
are always evaluated in list context.
print LIST
So reverse
will be evaluated in list context. That means it will reverse the order of its operands. It won't reverse the order of the characters of each operand, and it won't concatenate the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With