Re: substr forces scalar context with array argument
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 29 Nov 2005 08:12:09 -0800
Andrew wrote:
> #-------------- output -------------------
>
> substr($s, $offset, $length) ---> acad
> substr($s, @tmp) ---> racadabra
> substr($s, @tmp[0,1]) ---> cadabra
> substr($s, $tmp[0], $tmp[1]) ---> acad
>
> #------------ end output ----------------
>
> ( Also, FWIW, using '@tmp[0,1]' yields a weird result I can't explain )
Didn't see this comment originally. The issue here is that a list
slice returns a list, not an array. A list in scalar context returns
the last item of that list. Therefore,
substr($s, @tmp[0,1]);
is equivalent to:
substr($s, 4);
since $tmp[1] == 4.
Paul Lalli
.
- References:
- substr forces scalar context with array argument
- From: Andrew
- substr forces scalar context with array argument
- Prev by Date: Re: substr forces scalar context with array argument
- Next by Date: Re: length is 0 with unpack_socketaddr_in
- 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
|