Perl Home
PERL Functions
© 2011 TutorialsPoint.COM
|
PERL pos Function
Syntax
Definition and Usage
Used to find the offset or position of the last matched substring. If SCALAR is specified, it will return the offset of the last match on that scalar variable. You can also assign a value to this function (for example, pos($foo) = 20;) in order to change the starting point of the next match operation.
Offset is counter starting from zeroth position.
Return Value
In scalar context, Interger
In list context, then positions of all the matches within the regular expression
Example
Try out following example:
#!/usr/bin/perl -w
$name = "This is alpha beta gamma";
$name =~ m/alpha/g;
print("pos() ", pos($name), "\n");
|
It will produce following results:
|

|
|
|