I'm curious if Perl internals creates a copy of the ref values to create the array? For example, the following outputs the last and first value of a delimited string:
say @{[ split( q{\|}, q{bar|is|foo} ) ]}[-1,0]; # STDOUT: foobar\n
- Does the operation first generate a list via
split
and create an array ref, then copy the values of the array ref into a new array when dereferencing? - Does it morph the current arrayref in place?
Because dereferencing is so common I'm sure it's optimized, I'm just curious how expensive it is versus creating an array from the list initially, like:
my @parts = split q{\|}, q{bar|is|foo};
say @parts[-1,0];
Purpose: getting an idea of the underlying operations w/o getting too deep into the code