in reply to Re^2: why can't I shift a split?
in thread why can't I shift a split?

TY Kind and Wise Monks for these replies. Ken- it's reassuring to know that at least in some Perl-verse this is legal or at least considered.

What I'm seeking is the LAST array element; I want shift to toss the top one.

this is similar to something else I often do successfully:

@_ = split /,/,join "\n",$myscalar
I was trying to do something similar with shift.. I also tried
shift @_ = split /,/,join "\n",$myscalar
Which I thought had the best chance. Mr TVVALUT has a solution I'll try... I recognize the list/ARRAY difference which is why I was trying various "@{}" constructs to coerce it. Seems like if I can split a join, then I ought to be able to shift a split!

TY all!

Replies are listed 'Best First'.
Re^4: why can't I shift a split?
by tybalt89 (Monsignor) on Aug 25, 2022 at 17:04 UTC

    "LAST array element"

    my $last = ( split /,/,join "\n",$myscalar )[-1];
      This

      join "\n",$myscalar

      looks like a useless no-op.

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

        Sure, but let's just fix one problem at a time :)

Re^4: why can't I shift a split?
by Anonymous Monk on Aug 26, 2022 at 16:43 UTC

    If you want the last element of a split(), try this: ( split ... )[-1].