What are the various Perl data types based on the context?

devquora
devquora

Posted On: Feb 22, 2018

 

Perl data types are treated differently based on the context in which they are accessed. They are-
  • Scalar Context: It accesses data items as scalar values. Scalar context can be further divided into string context, numeric context and don’t-care context. Scalar context simply returns the whatever kind of scalar value they want to and let PERL convert numbers to strings in string context and strings to numbers in numeric context. Sometimes, the scalar contexts don’t care whether a string, number or a reference is returned, so no conversion happens in that case.
  • List Context: It treats the lists and hashes as atomic objects. Assignment to an array or a hash evaluates the right-hand side in the list context.
  • Boolean Context- It is a place where an expression is evaluated to check whether it’s true or false. It is “true” when then the scalar value is not the null string. Boolean doesn’t let any conversions to happen since it is a don’t-care context.
  • Void Context: This context neither cares for the type of the return value nor does it want a return value. It is no different from an ordinary scalar context from the standpoint of how functions work.
  • Interpolative Context: This context only happens inside a quote or things that act like a quote.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Perl Interview Questions

    List all the features of Perl programming.

    Practical extraction and reporting language (PERL) is an open source software which is used to develop web-based applica..

    Perl Interview Questions

    What are the benefits of PERL in using it as a web-based application?

    The benefits of using PERL programming are: PERL is known as the duct tape of the internet. PERL can accelerate the pro..

    Perl Interview Questions

    Talk about the applications of PERL.

    PERL has myriad and varied applications. PERL is used to write Common Gateway Interface scripts and large projects like..