in reply to Match all Non-0 and Letters
as other monks have already mentioned, all you really need is a single regex such as /0{7}\d/ (or perhaps /^0{7}\d$/ if the word you get is just the number).
You could, however, split your word into two parts as you did, but you made a logical error: you should have a "or", not an "and" in your condition for detecting a corrupt word, because you want to detect if the first part is not made of 0 OR if the second part is not a digit. So, you might fix your code as follows:
But, again, this was just to explain the error in your code, the solution with /0{7}\d/ is much simpler and better.my $Disc = get_word(); my $D1 = substr($Disc,0,7); my $D2 = substr($Disc,7,1); print "Word $Disc is corrupt!\n" if $D1 !~ /0+/ or $D2 !~ /[0-9]+/;
Update: this was intended to show the logical error ("and" instead of "or"). As pointed out by AnomalousMonk just below, the regexes are also wrong in terms of the intended purpose described in the original post.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Match all Non-0 and Letters
by AnomalousMonk (Archbishop) on Jun 24, 2017 at 17:34 UTC | |
by Laurent_R (Canon) on Jun 24, 2017 at 17:58 UTC | |
by AnomalousMonk (Archbishop) on Jun 24, 2017 at 18:44 UTC |