[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: going OT: moving to perl



On Sat, Jul 06, 2002 at 11:29:40PM -0100, andrej hocevar wrote:
> Frankly, it's just a quick question: in perl, is there a way of
> doing something like ${var:x:y}, x and y being numbers, the starting
> point and the lenght to be printed?

It sounds like you want substr.  Assuming $var is a scalar, then

  substr($var, $x, $y)

returns a substring of length $y of $var, beginning with position $x.
For example, if you have

  $var = "abcdefg";

then

  substr($var, 2, 3)

returns "cde".

Like most other things in Perl, there are a number of different ways
to call substr.  See "perldoc -f substr" for more information.

Walt

Attachment: pgpyi8qDXN4x5.pgp
Description: PGP signature


Reply to: