Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Perl Object Initilization

by rev_1318 (Chaplain)
on Jun 09, 2011 at 17:44 UTC ( [id://908967]=note: print w/replies, xml ) Need Help??


in reply to Perl Object Initilization

Something like:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; package Test; sub new { my ($class, @args) = @_; my $self = {}; bless $self, $class; $self->init(@args); return $self; } sub init { my ($self, @args) = @_; %$self = ( a => 10, b => 20, @args, ); return $self; } package main; my $test1 = Test->new(); print "$test1->{a}\n"; my $test2 = Test->new(a => 40); print "$test2->{a}\n";
init sets defaults, which you can override with your values...

Paul

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-19 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found