Numeric, String, and Boolean Context

Learn about numeric, string, and boolean contexts in Perl.

Value context

Perl’s other context—value context—influences how Perl interprets a piece of data. Perl can figure out if we have a number or a string and convert data between the two types. In exchange for not having to declare explicitly what type of data a variable contains or a function produces, Perl’s value contexts provide hints about how to treat that data.

Coercion and contexts

Perl will coerce values to specific proper types depending on the operators we use. For example, the eq operator tests whether two values contain equivalent string values:

Get hands-on with 1200+ tech skills courses.