Solved

case match

Posted on 2000-04-06
2
162 Views
Last Modified: 2010-03-05
i try to do this so that when $case is yes i will use the while
loop as normal
ie
while( $text =~ /\s*([^.!?]*\Q$word\E[^.!?]*[.!?])/g ){
but when $case is no it should be
while( $text =~ /\s*([^.!?]*\Q$word\E[^.!?]*[.!?])/gi ){
(note that "i" is inserted at the end)

but i cant get it to work


if($case eq "no"){
$casechoice = 'i';
}
else{
$casechoice = ' ';
}


while( $text =~ /\s*([^.!?]*\Q$word\E[^.!?]*[.!?])/g$casechoice ){
etc.....
0
Comment
Question by:boofulls
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 2691502
if( $casechoice eq 'i' ){
    while( $text =~ /\s*([^.!?]*\Q$word\E[^.!?]*[.!?])/g ){ }
}else{
    while( $text =~ /\s*([^.!?]*\Q$word\E[^.!?]*[.!?])/gi ){ }
}
#or
 while( $text =~ /(?$casechoice:\s*([^.!?]*\Q$word\E[^.!?]*[.!?]))/g ){ }
0
 
LVL 1

Expert Comment

by:mrachow
ID: 2692696
Comment only:
Usually substitution takes place on strings only. If you want it to be done on a command you first have to deal with your cammand as a string like:
$letters = word;
$line      = "This     Word should    be found";

$casechoice = 'i';
$cmd = "\$line=~/\\b\$letters\\b/$casechoice;";

if( eval $cmd)
{
  print "Found\n";
}

And execute it later by eval. (The return value will be this of the last command at string.)
But obviously the search strings becomes much more difficult because one had to prevent to early substitution and escaping from taking place.
So it would be more clear to do it in ozos way.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question