There's more than one way to do things | |
PerlMonks |
Re: Re: compare stdin for a numberby UnderMine (Friar) |
on Mar 12, 2004 at 22:32 UTC ( [id://336290]=note: print w/replies, xml ) | Need Help?? |
Hope you don't mind me making a few comments and I hope you find them helpful.
This is a good start ;) you might want to add use warnings; as well This looks like it has been though word :( Word uses odd quoting that changes the quote (") charecter and will capitalise first letters. Next bit looks ok but personally I would use a while (1) last loop. Next line has been nobbled by word again but there are also a couple of other issues. !=~ should be !~ there was a thread the other day covering exactly what !=~ does but don't go there it is bizzare. /[0-9][0-9][0-9][0-9]/ matches four digits true enough but it will match anything that contains 4 succesive digits (ie 'ABC12CD E3456FGH') and the original post asked for exactly 5 digits (ignoring the 4 - 5 issue ;)) you need to lock the pattern to the start (^) and end ($) of the string. /^[0-9][0-9][0-9][0-9]$/ would do this. Please use a text editor rather than word which alters what you write. De-worded this is fine. There is a problem with the following line but againg it is related to case sensitivity. The label you loop back to has to match including case. Other wise you get Label not found for "redo TEST" at - line 9, <STDIN> line 1. Should read :- No errors here. So reassembled :- This works and does the job. A very good start. Just please don't use word ;)
Hope it helps
In Section
Seekers of Perl Wisdom
|
|