[forwarded submission mistaken as an admin request by majordomo -- rjk]


From: Greg London <[EMAIL PROTECTED]>
Date: Sat, 14 Jul 2001 09:49:16 -0400
Subject: Re: [Boston.pm] overload
To: boston perl <[EMAIL PROTECTED]>

well, I found the answer to part of my question.
the following code does what I want:

{
package doppleganger;
use overload '%{}' => \&as_hash;
sub as_hash
{
        my $x=shift;
        my $hash_ref = 
        {
                zero=>$x->[0],
                one =>$x->[1],
                two =>$x->[2],
                three =>$x->[3],
        }
        return $hash_ref;
}

sub new
{
        my $class = shift;
        return bless [ @_ ] => $class;
}
}
package main

my $bar = new doppleganger 'alpha', 'bravo', 'charlie', 'delta';
my $val = $bar->{zero};
print "val is $val\n";

$val = $bar->[2];
print "val is $val\n";

this is a good starting point for me to work with.

I still don't understand the line noise in the
previous example, so if anyone could explain that,
I would appreciate it.
 
thanks,
Greg London

Reply via email to