in reply to why can't I shift a split?
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.
Others 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
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: why can't I shift a split? (List vs Array)
by misterperl (Friar) on Aug 26, 2022 at 14:07 UTC | |
by LanX (Saint) on Aug 26, 2022 at 23:15 UTC |