I don't think there's really a good reason from a language point of view why shift doesn't do what you want. It seems like an implementation issue. The interpreter could create a temporary array that can be modified by shift, but it just doesn't, because nobody thought it should. I'm not sure if I think it should or not.
You can get the "car" (couldn't they have thought of a better name?) of an array like this:
@x[1..$#x]
But that's ugly and probably inefficient. And you have to actually assign your list to @x first, so you can't wedge it into the middle of an expression. Too bad you can't give an open-ended array slice, like this:
(split / /, $string)[1..]
Perl arrays are different from lisp lists. Some things that are easy with one may not be easy with the other. How could it be otherwise?
Update: Did I get car and cdr mixed up again? I can't imagine how I could be so careless. Contents of address register, contents of decrement register - the difference couldn't be clearer!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.