Re: substr forces scalar context with array argument
- From: xhoster@xxxxxxxxx
- Date: 29 Nov 2005 17:16:15 GMT
"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
.
- Follow-Ups:
- Re: substr forces scalar context with array argument
- From: Andrew
- Re: substr forces scalar context with array argument
- References:
- substr forces scalar context with array argument
- From: Andrew
- substr forces scalar context with array argument
- Prev by Date: FAQ 4.41 How can I remove duplicate elements from a list or array?
- Next by Date: Re: substr forces scalar context with array argument
- Previous by thread: Re: substr forces scalar context with array argument
- Next by thread: Re: substr forces scalar context with array argument
- Index(es):
Relevant Pages
|