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); }
In reply to Re^4: RegExp substitution
by Keystone
in thread RegExp substitution
by Keystone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |