Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

substr documentation in perldoc

19 views
Skip to first unread message

Athanasius

unread,
May 3, 2012, 2:24:02 AM5/3/12
to
Hi,

Searching perldoc (Perl 5 version 14.1) for the built-in 'substr' function
gives:

> substr EXPR,OFFSET,LENGTH,REPLACEMENT
> substr EXPR,OFFSET,LENGTH
> substr EXPR,OFFSET
>
> Extracts a substring out of EXPR and returns it. First character is at
> offset 0 ...

Is "0" a typo for "OFFSET" -- that is, should the first sentence be: "First
character is at offset OFFSET..." -- or am I just confused?

Thanks,
Athanasius <°(((>< contra mundum

Owen

unread,
May 3, 2012, 2:33:30 AM5/3/12
to
On Thursday, May 3, 2012 4:24:02 PM UTC+10, Athanasius wrote:
> Hi,
>
> Searching perldoc (Perl 5 version 14.1) for the built-in 'substr' function
> gives:
>
> > substr EXPR,OFFSET,LENGTH,REPLACEMENT
> > substr EXPR,OFFSET,LENGTH
> > substr EXPR,OFFSET
> >
> > Extracts a substring out of EXPR and returns it. First character is at
> > offset 0 ...
>


No, that is 0, the way you count is 0,1,2, .... so the first character is at position 0. If the offset is say 3, then the string is taken from starting at the 4th character.


Owen

Jürgen Exner

unread,
May 3, 2012, 2:39:56 AM5/3/12
to
Read that as "first character _of_the_original_string_ is at offset 0,
i.e. if you want to retrieve the first character of the original string,
then you have to use offset 0.

jue

Athanasius

unread,
May 3, 2012, 8:59:44 AM5/3/12
to
"Jürgen Exner" <jurg...@hotmail.com> wrote:

> Read that as "first character _of_the_original_string_ is at offset 0,
> i.e. if you want to retrieve the first character of the original string,
> then you have to use offset 0.

Ok, I guess that makes sense. (But, I still think this way of putting
things reads like "documentation" =~ s/document/obfusc/ ;-) .)

Thanks Jue and Owen for your prompt replies.

Athanasius <°(((>< contra mundum

0 new messages