in reply to why can't I shift a split?

Oh drat I wasn't logged in! I also tried this fugly one:
$_='something,something else'; @_ = shift @ {split /,/ };
which is OK syntax wise, but results in "undef".

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

    But

    $_='something,something else'; @_ = shift @ {[split /,/ ]};
    does work.

      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!

        "LAST array element"

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

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