in reply to First occurance in a string
If $pattern is a literal string to find in $string, then parv is correct. Use index.
If $pattern is really a pattern and not a literal string to find in $string, you can do something like this:
my $string="/ae/gowtham_langTests/hpgl2/hpgl2/linepath/masters/top2bot +tom/top2bottom9/top2bott om9.plt1.tiff "; my $pattern = "/hpgl2/"; if ( $string =~ /\A(.*?)$pattern/ ) { print "place: ", length $1, "\n"; } print "index: ", index( $string, $pattern ), "\n"; __END__ place: 21 index: 21
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: First occurance in a string
by AnomalousMonk (Archbishop) on Aug 29, 2008 at 15:51 UTC | |
by toolic (Bishop) on Aug 29, 2008 at 17:10 UTC |