substr documentation in perldoc

Discussion in 'Perl Misc' started by Athanasius, May 3, 2012.

  1. Athanasius

    Athanasius Guest

    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
     
    Athanasius, May 3, 2012
    #1
    1. Advertising

  2. Athanasius

    Owen Guest

    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
     
    Owen, May 3, 2012
    #2
    1. Advertising

  3. "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
     
    Jürgen Exner, May 3, 2012
    #3
  4. Athanasius

    Athanasius Guest

    "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
     
    Athanasius, May 3, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kees Hoogendijk

    getline and substr

    Kees Hoogendijk, Dec 20, 2003, in forum: C++
    Replies:
    4
    Views:
    575
    Kees Hoogendijk
    Dec 21, 2003
  2. entropy123

    [C++] Odd Problem with "substr"

    entropy123, Jun 1, 2005, in forum: C++
    Replies:
    7
    Views:
    559
    Stephen Howe
    Jun 2, 2005
  3. David Resnick
    Replies:
    1
    Views:
    325
    Victor Bazarov
    Apr 10, 2006
  4. sks

    String - substr query

    sks, Jul 12, 2006, in forum: C++
    Replies:
    6
    Views:
    440
  5. Shashank Khanvilkar

    Perldoc: No documentation on perl found [newbie]

    Shashank Khanvilkar, Dec 10, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    149
    A. Sinan Unur
    Dec 10, 2004
Loading...

Share This Page