Scalar and List Contexts in Perl

One of the most important concepts to understand in Perl programming is that of evaluation based on context. In Perl, an operation such as an assignment or function call can give two different results based on the context of the expression. You see, in Perl, every operation behavior depends on the context in which it is called. A classic example is when using the “localtime” function. In a scalar context, the “localtime” function returns the current date and time. However, in a list context the function returns a nine-element list as shown below.

Perl code demonstrating evaluation based on scalar and list context


Output

This entry was posted in Perl, Programming Languages and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


nine − 8 =