Consider this code:
@tmp = split(/\s+/, "apple banana cherry");
$aref = \@tmp;
Besides being inelegant, the above code is fragile. Say I follow it with this line:
@tmp = split(/\s+/, "dumpling eclair fudge");
Now $$aref[1]
is "eclair" instead of "banana".
How can I avoid the use of the temp variable?
Conceptually, I'm thinking of something like
$aref = \@{split(/\s+/, "apple banana cherry")};
You could do this if you want an array-ref:
my $aref = [ split(/\s+/, "apple banana cherry") ];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With