in reply to Re^3: RegExp substitution
in thread RegExp substitution
After running through each of the <STDIN>'s the final print is "Four, Four, Four, Four" - in retrospect this is possibly the closest I got to my actual solution! This is what prompted me to ask the question where-in I was looking for a way to ignore the first match of a RegEx the second time it's run. Again, thank you for your help, I feel I am close to a solution. -- Just had a thoguht pre-posting, it is possible (but perhaps not elegant) to run the RegEx /A-Za-z+/, save the result to a variable and substitute the match with whitespace.. then call the variable later.. but thinking about it this is just a cheat/hack and not really using the substitute fnction of a RegEx. Regards Keystone#!/usr/bin/perl #subs4.plx use warnings; use strict; #try using /g global to remember where I'm up to in a match my $pattern; $_ = "Three, Four, One, Two"; print ("\t\tCounting Program\n\n", $_, "\n\n"); my $correct; print "Is this sequence correct?(yes/no)\n"; $correct = <STDIN>; chomp ($correct); while ($correct ne "yes"){ print "Is the first number correct?\n"; my $first = <STDIN>; chomp ($first); if ($first ne "yes"){ print"What should it be?\n"; $first = <STDIN>; chomp ($first); /([A-Z][a-z]+)/g; s/$1/$first/g; } print "Is the second number correct?\n"; my $second = <STDIN>; chomp ($second); if ($second ne "yes"){ print"What should it be?\n"; $second = <STDIN>; chomp ($second); /([A-Z][a-z]+)/g; s/$2/$second/g; } print "Is the third number correct?\n"; my $third = <STDIN>; chomp ($third); if ($third ne "yes"){ print"What should it be?\n"; $third = <STDIN>; chomp ($third); /([A-Z][a-z]+)/g; s/$3/$third/g; } print "Is the fourth number correct?\n"; my $fourth = <STDIN>; chomp ($fourth); if ($fourth ne "yes"){ print"What should it be?\n"; $fourth = <STDIN>; chomp ($fourth); /([A-Z][a-z]+)/g; s/$4/$fourth/g; } #Final print print ($_, "\n\n"); print "Is this sequence correct now?(yes/no)\n"; $correct = <STDIN>; chomp ($correct); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: RegExp substitution
by AnomalousMonk (Archbishop) on Apr 11, 2014 at 00:01 UTC | |
by Keystone (Initiate) on Apr 11, 2014 at 07:01 UTC |