I would like to have the scalar values of an array ref passed to a sub modified in-place. I must pass an array ref and I must modify the values in place. As you can see, the code below works fine with two different calling conventions.
my $count = 1; sub modify { my $aref = $_[0]; ${$aref->[1]}=$count++; } sub prelayer { my $aref = shift; modify $aref; } my ($x, $mod) = (666,777); my @A = \($x, $mod); prelayer \@A; print $mod, $/; prelayer [ \$x, \$mod ]; print $mod, $/;

I was wondering if something like this would work:

prelayer([ $x, $mod ]);
if I could create some sort of special magic in the called subroutines. I would like for the calling syntax to be as clean as possible and do all the dirty work in my subroutines.

In reply to passing an array ref to subroutine and modifying its elements by princepawn

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.