Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: why can't I shift a split? (List vs Array)by LanX (Saint) |
on Aug 25, 2022 at 23:25 UTC ( [id://11146432]=note: print w/replies, xml ) | Need Help?? |
The fundamental problem here is that lists and arrays are two different things. That's a FAQ Lists are temporary data sequences which can't be changed! But Arrays are variable(s) with @sigils and they are changed. Shift can only operate on arrays, because they are shortened afterwards. Once you've understood this... > why can't I shift a split? Because split returns a list! Unless you assign it to an array it can't be shifted.
AddendumOthers have shown solutions with (lists)[slices] which work similar to @array[slices] . That's only possible because a slice doesn't change its object, unlike shift. Further reading
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|