[Israel.pm] List of all contexts in Perl

Offer Kaye offer.kaye at gmail.com
Sun May 30 02:09:52 PDT 2010


On Sun, May 30, 2010 at 12:56 AM, Mikhael Goikhman wrote:
>
> "perldoc overload" provides some enlightenment on the topic.
> Basically every group of operators described in this document can be
> (but not required to be) seen as a separate context. This includes:
>
>  * Arithmetic, Comparison, Bit operations
>  * Boolean, string and numeric conversion: 'bool', '""', '0+'
>  * Iteration: '<>'
>  * Matching: '~~'
>  * Dereferencing: '${}', '@{}', '%{}', '&{}', '*{}'
>
> Regards,
> Mikhael.
>

I understand list/scalar context. This is a way of looking at how a
Perl statement is called and how it can return different values
depending on the way it is called.

I'm not sure I understand what "boolean context" means, or any of the
others you listed. Except for the ".." operator does any of Perl's
built-in functions operate differently inside an "if" test for
example, in terms of the value returned (assuming you assign it to
something)?

Looked at another way, you can do anything you want with the return
value of for example "localtime", but in the end it will still return
either a scalar or list, regardless of what you do with those values
later on, right?

I have to admit though, even the official "perlop" and "perlsyn" talk
about "boolean context" so maybe I'm missing something :)

Regards,
--
Offer Kaye


More information about the Perl mailing list