Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: An overloaded object and tie

by eclark (Scribe)
on Jun 09, 2004 at 18:02 UTC ( #362828=note: print w/replies, xml ) Need Help??


in reply to An overloaded object and tie

Try looking at Tie::Array.

Replies are listed 'Best First'.
Re^2: An overloaded object and tie
by Anonymous Monk on Jun 09, 2004 at 19:17 UTC
    Hi, I've already tried this - it doesn't work in the way I thought/wanted it to:
    package Tie::NewStdArray; use Tie::Array; @ISA = ('Tie::StdArray'); sub STORE { print 'in store'; } sub FETCH { print 'in fetch'; } # all methods provided by default package main; my @somearray; my $object = tie @somearray,Tie::NewStdArray; $somearray[0]=12; #intercepted by tie $object[0]=12; #uses the blessed array
    Using the object returned from tie uses the blessed reference not the tie, which means you can't use the [] syntax when object are created on the fly by overloading. For example:
    $three=$two+$one; print $three[12];

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://362828]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-05-23 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?