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.
while (<>) { print if(/\s0/); }
If I just use this:
while(<>) { print if(/0/); }
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.

jjdraco
learning Perl one statement at a time.

In reply to problems with regular expressions by jjdraco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.