Anybody wanted to have an array slice which can *modify* the original ? (Something not happening with the @array{..} slice notation).
Here is a solution with just a minor cosmetic annoyance:
WHATSIT: Create an array of lvalue anon's stored in an array, which then return the value (as an lvalue, which means it modifies the original).
use Data::Dump qw(dump);
my @dna = qw(A T T G C);
print dump \@dna;
my @view = (
sub : lvalue { $dna[1] },
sub : lvalue { $dna[2] },
);
#mutate
$view[0]->() = 'x';
$view[1]->() = 'x';
print dump \@dna;
$view[0] = sub : lvalue { $dna[4] };
print dump \@dna;
# print ["A", "T", "x", "G", "x"]
Imperfect: If you want to use the view in exchange to the original array, it does not work for this reason: the
$view[0]->()
notation (which calls the lvalue anon). One would have to find a way how this notation shall work
$view[0]
instead.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.