Hello,

The following has nice one-liners for assigning parameters during initialization and for destroying parameters during destruction. However, I could not come up with any nice way to implement the tedious set and get sub-routines -- what's a nice way to implement them?

package ThePackage; use diagnostics; use warnings; use strict; use Scalar::Util qw(refaddr); use Carp; $Carp::Verbose = 1; { my ( %parameter_a_of, %p_b_of, %param_c_of, %parameter_d_of, ) = (); my %init_aid = ( paramater_a => \%parameter_a_of, p_b => \%p_b_of, paramater_c => \%param_c_of, paramater_d => \%parameter_d_of, ); sub new { my($class, $parameter_a, %h) = @_; my $new_object = bless \do{my $anon_scalar}, $class; $paramter_a_of{refaddr $new_object } = $parameter_a; defined $h{$_} and ${$init_aid{$_}}{refaddr $new_object} = $h{$_} for (keys %init_aid); return $new_object; } sub DESTROY { my ($self) = @_; delete ${$init_aid{$_}}{refaddr $self } for (keys %init_aid); return; } sub get_parameter_a { return $parameter_a_of{refaddr $_[0]} } sub get_p_b { return $p_b_of {refaddr $_[0]} } sub get_param_c { return $param_c_of {refaddr $_[0]} } sub get_parameter_d { return $parameter_d_of{refaddr $_[0]} } sub set_parameter_a{ $parameter_a_of{refaddr $_[0]} = $_[1]; return; + } sub set_p_b { $p_b_of {refaddr $_[0]} = $_[1]; return; + } sub set_param_c { $param_c_of {refaddr $_[0]} = $_[1]; return; + } sub set_parameter_d{ $parameter_d_of{refaddr $_[0]} = $_[1]; return; + } }


In reply to Any one-liners for set and get functions? by sg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.