Solved

case match

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now