Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Overloading '='

by dchetlin (Friar)
on Sep 23, 2000 at 16:38 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://33772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-16 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found