Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > substr documentation in perldoc

Reply
Thread Tools

substr documentation in perldoc

 
 
Athanasius
Guest
Posts: n/a
 
      05-03-2012
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

 
Reply With Quote
 
 
 
 
Owen
Guest
Posts: n/a
 
      05-03-2012
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 isat
> > 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
> 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


 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      05-03-2012
"Athanasius" <Athanasius@invalid> wrote:

>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?


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
 
Reply With Quote
 
Athanasius
Guest
Posts: n/a
 
      05-03-2012
"Jürgen Exner" <> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String - substr query sks C++ 6 07-13-2006 02:12 AM
is assigning a substr to the parent str OK? David Resnick C++ 1 04-10-2006 02:43 PM
[C++] Odd Problem with "substr" entropy123 C++ 7 06-01-2005 11:38 PM
Perldoc: No documentation on perl found [newbie] Shashank Khanvilkar Perl Misc 3 12-10-2004 10:38 PM
getline and substr Kees Hoogendijk C++ 4 12-21-2003 10:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57