|Syntactic Confectionery Delight|
problems with regular expressionsby jjdraco (Scribe)
|on Oct 05, 2002 at 03:49 UTC||Need Help??|
jjdraco has asked for the
wisdom of the Perl Monks concerning the following question:
As I attempt to learn Perl I've looked over the internet several times trying to find programming examples to practice on. Well I cam across a website that has lots of challenging problems at ACM. The problem I'm working on is from they're '96 contest problem A. Well the problem I'm having is how they want it read it, I understand it as the want it read from the STDIN. The input is decks of cards and kings, queens, and jacks are all represented as the value 10 ace as the value 1. the input is supposed to be terminated by the number zero (0) but the problem didn't say it had to be on its own line. As a matter of fact it said that the cards for each deck read in could be seperated by a space or a newline. I've come up with some code that would work if i were reading it from a file, thats not the problem. but if i readd it from STDIN i can't seem to find the regex that would make the number zero (0) with out matching the number ten (10) as well. I've read through String matching and Regular Expressions and perlre, but i was unable to get clearification on this matter. i've also tried just experimenting, but the only thing i found was i can get find the zero as long as its not the first number in the string i.e.
If I just use this:
it prints the case when zero is the first number but it also prints when it finds any number with a 0 in it (i.e. 10, 20, 30)
I just can't figure it out. besides that i think i almost have the problem solved, besides a few bugs in the test case of a draw. but i have ideas of how i'm going to do it if i can just get the rest of the code working and this one thing is the only thing killing me right now.
The only other thing I can think to do is instead of reading it in a line at a time I could try reading in a charector at a time, but I'm not sure if that would be better or not.
learning Perl one statement at a time.