Keystone has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RegExp substitution
by AnomalousMonk (Archbishop) on Apr 10, 2014 at 17:29 UTC | |
by Keystone (Initiate) on Apr 10, 2014 at 20:17 UTC | |
by AnomalousMonk (Archbishop) on Apr 10, 2014 at 22:40 UTC | |
by Keystone (Initiate) on Apr 11, 2014 at 07:17 UTC | |
by HereandThere (Initiate) on Apr 10, 2014 at 20:55 UTC | |
by Laurent_R (Canon) on Apr 10, 2014 at 21:47 UTC | |
by Keystone (Initiate) on Apr 10, 2014 at 21:31 UTC | |
by AnomalousMonk (Archbishop) on Apr 11, 2014 at 00:01 UTC | |
| |
by AnomalousMonk (Archbishop) on Apr 10, 2014 at 22:23 UTC | |
by AnomalousMonk (Archbishop) on Apr 11, 2014 at 00:40 UTC | |
by Keystone (Initiate) on Apr 11, 2014 at 07:19 UTC | |
|
Re: RegExp substitution
by AnomalousMonk (Archbishop) on Apr 11, 2014 at 05:04 UTC | |
|
Re: RegExp substitution
by MidLifeXis (Monsignor) on Apr 10, 2014 at 18:01 UTC | |
by Bloodnok (Vicar) on Apr 10, 2014 at 18:41 UTC | |
by MidLifeXis (Monsignor) on Apr 10, 2014 at 19:05 UTC |