edwardt_tril has asked for the wisdom of the Perl Monks concerning the following question:

very new to object oriented perl and the following already amkes my head spins... please help me understand thanks
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
    Regarding the keys question comment in the code, keys %default_fields returns the keys of %default fields. perldoc -f keys

    By the way, when posting, it would be helpful to include all your questions outside of your code, not just in comments inline.

      Or at least delineate the comments from the code better; say . . .

      ## ## I don't understand x about the following line . . . ## evil_code_goes_here( . . . )

      As is they don't really stand out from the code proper.

Re: Please Explain This Constructor
by izut (Chaplain) on Mar 10, 2006 at 19:10 UTC
    perldoc -f exists

    Igor 'izut' Sutton
    your code, your rules.

Re: Please Explain This Constructor
by QM (Parson) on Mar 10, 2006 at 19:13 UTC
    What don't you understand? Or, what do you think it should do?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of