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

But

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

Replies are listed 'Best First'.
Re^3: why can't I shift a split?
by misterperl (Friar) on Aug 25, 2022 at 16:58 UTC
    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];
        This

        join "\n",$myscalar

        looks like a useless no-op.

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

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