Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL index Function



Syntax

index STR, SUBSTR, POSITION

index STR, SUBSTR


Definition and Usage

Returns the position of the first occurrence of SUBSTR in STR, starting at the beginning (starting at zero), or from POSITION if specified.

Return Value

  • -1 on failure otherwise Position of matching string (starting at zero for the first character).

Example

Try out following example:

#!/usr/bin/perl

$string = "That is test";

$index = index ($string, 'is');

print "Position of is in the string $index\n";

It produces following result

Position of is in the string 5



Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names