Greetings fellow Monks. It's been a few weeks. I'm happy to report I'm making good progress on a fairly extensive project of mine thanks to all the kind help found here.

So one thing that is annoying me right now is the process of populating scalars with object properties to make code more readable. For example:

sub function { my $self = shift; my $val1 = $self->get_value1; my $val2 = $self->get_value2; my $val3 = $self->get_value3; print "Values: $val1, $val2, $val3"; }

For me, I find transferring object properties to scalars is less error prone and makes code easier to read than something like: print "Values: " . $self->get_value1 . ', ' . $self->get_value2 . ', ' . ', ' . $self->get_value3"; or printf "Values: %s, %s, %s", $self->get_value1, $self->get_value2, $self->get_value3";

I know it's possible to do print "${\$self->get_value}" but that is just god awful.

Using scalars is also useful if I have to use a property several times in the same block of code or if there are many object properties to keep track of. It saves a lot of typing and, again, makes the code easier to read. But it still can be super annoying to create these scalars. I'm wondering if there might be some useful trick out there that will spare me the oh so tedium of creating scalars for my object properties. Thanks.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks


In reply to Method for reducing tedium of transferring object properties to scalars by nysus

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.