in reply to How can I use the the return value of split without assigning?

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!

Replies are listed 'Best First'.
Re: Re: How can I use the the return value of split without assigning?
by hding (Chaplain) on Jul 27, 2001 at 05:59 UTC

    You can get the "car" (couldn't they have thought of a better name?)... Did I get car and cdr mixed up again?I can't imagine how I could be so careless.

    In Common Lisp, you may freely use 'first' instead of 'car' and 'rest' instead of 'cdr' - they're completely identical. I tend to use first/rest when I'm thinking of something as a list, and car/cdr when I'm thinking of it as a cons cell, but that's hardly a hard and fast rule, even for me.