http://www.perlmonks.org?node_id=1014081

dicty has asked for the wisdom of the Perl Monks concerning the following question:

What's the meaning of index offset?

Thanks a lot!

Dicty

Replies are listed 'Best First'.
Re: index offset mean?
by Athanasius (Archbishop) on Jan 18, 2013 at 16:33 UTC

    Perhaps the following entry from the Camel Book Glossary will shed some light:

    offset
    How many things you have to skip over when moving from the beginning of a string or array to a specific position within it. Thus, the minimum offset is zero, not one, because you don’t skip anything to get to the first item.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: index offset mean?
by muba (Priest) on Jan 18, 2013 at 16:44 UTC

    Perhaps this little sample script will demonstrate the definition.

    $ perl -e ' my $string = "Lorem ipsum"; my @array = qw(The quick brown fox jumps over the lazy dog); for my $offset (0..length($string)) { printf "Offset $offset: %s\n", substr($string, $offset); } for my $offset (0..$#array) { printf "Offset $offset: %s\n", $array[$offset]; } ' Offset 0: Lorem ipsum Offset 1: orem ipsum Offset 2: rem ipsum Offset 3: em ipsum Offset 4: m ipsum Offset 5: ipsum Offset 6: ipsum Offset 7: psum Offset 8: sum Offset 9: um Offset 10: m Offset 11: Offset 0: The Offset 1: quick Offset 2: brown Offset 3: fox Offset 4: jumps Offset 5: over Offset 6: the Offset 7: lazy Offset 8: dog $
Re: index offset mean?
by Anonymous Monk on Jan 19, 2013 at 07:26 UTC