<?xml version="1.0" encoding="windows-1252"?>
<node id="170579" title="Re: Re: Basic Objects with Overloaded Operators" created="2002-05-30 21:31:34" updated="2005-07-19 14:07:41">
<type id="11">
note</type>
<author id="82147">
Zaxo</author>
<data>
<field name="doctext">
&lt;p&gt;The Camel, 3ed. has an example:&lt;code&gt;
package LuckyDraw;
use overload
    '&lt;&gt;' =&gt; sub {
        my $self = shift;
        return splice @$self, rand @$self, 1;
    };
sub new {
    my class = shift;
    return bless [@_] -&gt; $self;
}
1;
&lt;/code&gt;The book does not discuss the rules, but I'm sure this example breaks some of them. To work with &lt;tt&gt;while (&lt;$foo&gt;){}&lt;/tt&gt;, I think the return value should be true in 'bool' context until the source is exhausted. To cope with &lt;tt&gt;my @shuffle=&amp;lt;$deck&amp;gt;;&lt;/tt&gt; and with slices, a [wantarray] clause should be there to shuffle and return the whole $deck, leaving $deck empty.&lt;/p&gt;
&lt;p&gt;The rules you observe should only be the ones you &lt;em&gt;need&lt;/em&gt; to observe.&lt;/p&gt;
&lt;p&gt;After Compline,&lt;br/&gt;Zaxo&lt;/p&gt;
</field>
<field name="root_node">
8076</field>
<field name="parent_node">
168794</field>
</data>
</node>
