Solved

case match

Posted on 2000-04-06
2
170 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

766 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