Hi all, new to Perl and working through Simon Cozens free Beginning Perl book, tried to write myself a little program to test if I understood RegExp and it's not giving me the expected answers. Could anyone offer any guidance as to why the final print of $_ gives "FourThreeTwoOne, Three, Four, One, Two" please? As I said I'm only a novice, please be gentle!:)
#!/usr/bin/perl #subs.plx use warnings; use strict; #An incorrectly ordered list to have the user organise $_ = "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); } 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); } 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); } 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); } #My RegExp /([A-Z][a-z][.][\b])/; #The substitutions based on my RegExp s/$1/$first/; s/$2/$second/; s/$3/$third/; s/$4/$fourth/; #Final print reads:FourThreeTwoOne, Three, Four, One, Two print ($_, "\n\n"); print "Is this sequence correct now?(yes/no)\n"; $correct = <STDIN>; chomp ($correct); }
Anby guidance would be appreciated, Cheers, Keystone.
In reply to RegExp substitution by Keystone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |