index($str, [but with regex here])

E

Emanuel Berg

I have this line:

my $end = index($end_str, " ");

What I need, is the same (an integer position), only the first
word delimiter should be taken from a set of possible chars: not
only whitespace, but end of line, parenthesis, etc.

I need to be able to define this char by char: for example, I
*don't* want the slash to be such a delimiter.

What do you think?
 
J

Jürgen Exner

Emanuel Berg said:
I have this line:

my $end = index($end_str, " ");

What I need, is the same (an integer position), only the first
word delimiter should be taken from a set of possible chars: not
only whitespace, but end of line, parenthesis, etc.

I need to be able to define this char by char: for example, I
*don't* want the slash to be such a delimiter.

If nothing else you can always do it in two steps (error handling
omitted):

$end_str =~ m/([MyReClass])/;
$end = index($end_str, $1);

Replace MyReClass with whatever character set you like.

jue
 
E

Emanuel Berg

Thanks both. I only tried Ben's solution, as he was first and it
worked like a charm. I appreciate the crisp explanations.
 
J

Jim Gibson

Emanuel Berg said:
Thanks both. I only tried Ben's solution, as he was first and it
worked like a charm. I appreciate the crisp explanations.

You could also use the String::Index module from CPAN, which gives you
the equivalent of C's strpbrk function (I have not used it).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top