Perl6 Object Oriented Cookbook (v0.2.1)  
Section 1: Introduction to Object Oriented Perl6  
 
Recipe 1.7: Using Built-in Types as Objects
Last Updated: Sep 8, 2003
Status: Likely
      Previous Page   Next Page

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

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

Problem:  

You want to use a builtin type -- like a number, string, list, or hash -- as if it were an object.

Solution:  

Just do it:

my $var = "Now is the winter of our discontent... ";
print $var.length;

my %hash = ( key1 => 'val1', key2 => 'val2' );
print %hash.keys;
print %hash.values;

Discussion:

All internal types in perl6 are objects (or more precisely, they are promoted to objects if you choose to use them that way.) You can therefore call object methods on any builtin type. See later recipes for what methods are available for each builtin type.


Log In to Comment


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