Re: substr forces scalar context with array argument



Andrew wrote:
> >
> >Because substr has a prototype demanding scalars.
> >
> >~/perl_misc:$ perl -le 'print prototype "CORE::substr"'
> >$$;$$
>
> Is there a reason the prototype is demanding scalars? (Or is it simply
> "the king's decree"?)

Because it makes the most sense to use a scalar there.

> Again, in my observation and experience, perl particulars are designed
> with careful consideration of all the tradeoffs, and the most optimal
> (and usually intuitive) alternative is chosen (for syntax and
> functionality).

Yes. As it is here. Yours is the first post I can ever remember
seeing wishing it was the other way around.

> >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.
>
> Assuming that with the above you are rebutting my comment that "the
> word 'scalar' is nowhere to be found...": So the documentation does not
> mention either lists or scalars, which may leave the reader guessing.
> So, the purpose of my response to yours is to prevent the quick
> dismissal of the notion that the documentation /may/ need to be a bit
> more explicit. Although, admittedly, I may be wrong about that...
> particularly, if this is covered somewhere else in the docs.

You should probably read the first two paragraphs of
perldoc perlfunc
which is the overall enclosing entity of the `perldoc -f` syntax.

Paul Lalli

.


Quantcast