It's funny, I was trying to explain why it's not working, and I got really confused myself! LOL Here's what I began to write:

When you do shift split, the shift() function not only returns the first element of an array, but it also tries to REMOVE that element from an array, which it must be able to do. Demo:

#!/usr/bin/perl use strict; use warnings; my @A = (234, 405, 55, 1900); print "\n", shift(@A); # Prints 234 #print "\n", shift(234, 4, 55, 1900); # Error: Can't overwrite +the array, because it's fixed. #print "\n", shift( split(/\+/, '12+34+56+78') ); # Error: Can't over +write the array, because it's fixed. my $X = 3; print "\n", INCREMENT($X); # Prints 4. #print "\n", INCREMENT(3); # Error: Can't overwrite 3, because it's + fixed. print "\nNOW: $X"; # Prints 4. No error. print "\n", INCREMENT( $X + 3 ); # Prints 8. No error. print "\nTHEN: $X"; # Prints 4. No error. #print "\n", shift( @A, split(/\+/, '12+34+56+78') ); # Error. Can't +do this. # Kind of weird. That's not what I expected. :P exit; sub INCREMENT { ++$_[0]; }

See also: lvalue


In reply to Re: why can't I shift a split? by harangzsolt33
in thread why can't I shift a split? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.