Perl6 Object Oriented Cookbook (v0.2.1)  
Section 1: Introduction to Object Oriented Perl6  
 
Recipe 1.8: Using Literal Values as Objects
Last Updated: Sep 8, 2003
Status: Draft
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
4.60 Rating, 5 Votes  

How acceptable is the proposed solution?
  (Login to Vote)
5.00 Rating, 5 Votes  

Problem:  

You want to use a literal value as if it were an object.

Solution:  

Just do it:

print "a literal string".length;

print { key1 => 'val1' }.keys;

Discussion:

A literal value is nothing more than a specific (constant) instance of a builtin type or class; as such, you may call methods on literal values in the same manner as you call them on any other builtin types.


Log In to Comment


Login / Edit User Info -- Copyright © 2002 Cognitivity -- Previous Page   Next Page