edwardt_tril has asked for the wisdom of the Perl Monks concerning the following question:
my %default_fields =( desired_temp =>4, desired_volume=>qw[/1 2 3 4 5/], desired_mark=>100 ); my @required_fields=qw/location/; my @fields =(keys %default_fields,@required_fields); #I don't quite get what the part keys %default_fields) .. I # know it +put and expand everything into the @fields array sub new { my ($class,%args)=@_; foreach (@required_fiels) { #what does exists($args{$_}}means\? exists($args{$_}) or croak('required fieds $_ omitted"); } %args = (%default_fields,%args); #either set to defaults or new valu +es @this{@fields} = @args{@fields}; #this create a this array of array and set the contents to args return bless(\%this,$class); }
2006-03-11 Retitled by g0n, as per Monastery guidelines
Original title: 'can someone explain'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Please Explain This Constructor
by duckyd (Hermit) on Mar 10, 2006 at 19:54 UTC | |
by Fletch (Bishop) on Mar 10, 2006 at 22:12 UTC | |
|
Re: Please Explain This Constructor
by izut (Chaplain) on Mar 10, 2006 at 19:10 UTC | |
|
Re: Please Explain This Constructor
by QM (Parson) on Mar 10, 2006 at 19:13 UTC |