A lot of what you said isn't correct. For example, you said:
I'm also a fan of using references when passing large chunks of text (string variables) around to be used in various subroutines. This again boils down to not having to copy contents of a variable.
This is erroneous, because when you pass a string to a subroutine, Perl does not copy the contents of the variable. And you made the same mistake when you named one of your example subroutines by_val. Perl does not pass scalar data by value. Scalar data is always passed by reference, whether you use an explicit reference or not.

Consider:

sub trim { $_[0] =~ s/^\s+//; $_[0] =~ s/\s+$//; $_[0]; } my $var = " I like pie. "; trim($var); print $var;
The call to the trim function actually modifies $var, because scalar data is passed by reference, not by value. The value of $var is not copied.

The technique you suggest is more useful for arrays and hashes. foo(@array) passes a (possibly long) list of scalars to foo(), but foo(\@array) passes only a single reference.

--
Mark Dominus
Perl Paraphernalia


In reply to Re: Trying to learn about References by Dominus
in thread Trying to learn about References by dru145

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.