Solved

case match

Posted on 2000-04-06
2
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries PERL Scripts 7 207
Excel to CSV conversion with specific columns 5 111
PERL - Find newest folder 12 195
make a default program in ubuntu 6 24
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

739 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