Re: substr forces scalar context with array argument



"Andrew" <hawk007@xxxxxxxxx> wrote:
> In the code below, the array '@tmp' with two elements is treated as its
> scalar (the number 2), when used as argument to substr. When I
> syntactically break up '@tmp' into '$tmp[0]' and '$tmp[1]', substr does
> what i want. Why is this so?

Because substr has a prototype demanding scalars.

~/perl_misc:$ perl -le 'print prototype "CORE::substr"'
$$;$$


> Is there a way to force list context
> (besides explicit enumeration)? I can't seem to find any mention of
> this anywhere.

perldoc -f substr

substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET

Nowhere does it say LIST, so I wouldn't expect it to take an array
interpretted as a list.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.



Relevant Pages