in reply to Re: why can't I shift a split? (List vs Array)
in thread why can't I shift a split?

Rolf yes, I know that- but it should be EZ to coerce a list into an array?
  • Comment on Re^2: why can't I shift a split? (List vs Array)

Replies are listed 'Best First'.
Re^3: why can't I shift a split? (List vs Array)
by LanX (Saint) on Aug 26, 2022 at 23:15 UTC
    > should be EZ to coerce a list into an array

    sure:

    DB<2> p shift @{[42..59]} 42

    or

    DB<3> $shift = sub { shift @{$_[0]} } DB<4> p [42..59]->$shift 42

    but it doesn't make sense since the resulting shortened array is destroyed right away.

    Using a list slice is the logical° and easiest approach, without wasting operations.

    DB<5> p (42..59)[0] 42

    compare an array slice which wastes resources again, by allocating an array in memory which is destroyed again.

    DB<6> p [42..59]->[0] 42

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) and "implementing" pop list is symmetrical (42..59)[-1]