Is it possible to reference a specific array element? For instance:

my @array = (21..102); my $ref = \$array[5]; $$ref = 4; print $array[5];

Essentially I want to be able to pass this reference to an element of the array to a sub for editing. Or more precicely, I want to go through the array one element at a time and pass one argument at a time to another function for modification. Any idea how I would go about this? Is it even allowed? While I do use normal refs on a regular basis, this is something I'm clueless for... so any help would be appreciated, down to a technical explanation of how they do referencing in perl. (I'm curious but I lack the skill in other languages to actually understand how perl itself was written... hehe)

Thank you for any assistance or advice as to other ways I could achieve this.

Note: I actually did try the equivilant of the above... yielded things like \45 instead of a reference...





My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)


In reply to reference to array element? by Flame

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.