Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Re: Basic Objects with Overloaded Operators

by Zaxo (Archbishop)
on May 31, 2002 at 01:31 UTC ( #170579=note: print w/replies, xml ) Need Help??

in reply to Re: Basic Objects with Overloaded Operators
in thread Basic Objects with Overloaded Operators

The Camel, 3ed. has an example:

package LuckyDraw; use overload '<>' => sub { my $self = shift; return splice @$self, rand @$self, 1; }; sub new { my class = shift; return bless [@_] -> $self; } 1;
The book does not discuss the rules, but I'm sure this example breaks some of them. To work with while (<$foo>){}, I think the return value should be true in 'bool' context until the source is exhausted. To cope with my @shuffle=<$deck>; and with slices, a wantarray clause should be there to shuffle and return the whole $deck, leaving $deck empty.

The rules you observe should only be the ones you need to observe.

After Compline,

Replies are listed 'Best First'.
Re^3: Basic Objects with Overloaded Operators
by Anonymous Monk on May 29, 2006 at 18:51 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://170579]
[choroba]: 20 months? :-o
[Discipulus]: up to 20 months.. but you'll be sure to remain unemployed

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-05-23 21:01 GMT
Find Nodes?
    Voting Booth?