Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Overloading '='

by dchetlin (Friar)
on Sep 23, 2000 at 16:38 UTC ( #33772=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      package MyPackage;
      sub new {
    ...
    
      package main;
      my $a = MyPackage::->new(1);
    
  2. or download this
      package main;
      my $b = $a;
    
  3. or download this
      my $c = $a + $b;
    
  4. or download this
      package MyPackage;
      use overload q/+/ => \&add;
    ...
      sub add {
          $_[0]->new( $_[0]->{foo} + (ref($_[1]) ? $_[1]->{foo} : $_[1]) )
      }
    
  5. or download this
      package main;
      my $c = $a + $b;
    
  6. or download this
      $b++;
    
  7. or download this
      package MyPackage;
      use overload q/++/ => sub { $_[0]->{foo}*=2; shift };
    ...
      package main;
      $d = $c;
      $d++;
    
  8. or download this
      package MyPackage;
      use overload q/=/ => sub { $_[0]->new($_[0]->{foo}) };
    
  9. or download this
      package main;
      $d = $c;
    
  10. or download this
      $d++;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2015-07-31 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (282 votes), past polls