Solved

case match

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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.…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

23 Experts available now in Live!

Get 1:1 Help Now