++ to you for designing before you code. It's hard work, but the hard work pays off. Unfortunately, not in the short run. Your pseudo code has a few problems, and while you have the main section mostly finished, you mention nothing of what it means to shuffle, pull cards, or what a card or group of cards look like.

First, the main section revisited. I am going to call a collection of cards a deck.

create deck
shuffle deck

this_card = pull from deck
last_card = this_card
answer    = prompt('higher or lower')

for (rest of cards):
   this_card = pull from deck

   exit('was higher') if this_card > last_card and answer is 'lower'
   exit('was lower') if this_card < last_card and answer is 'higher'

   answer = prompt('higher or lower')
   last_card = this_card
end for
By using two variables, this_card and last_card, we can compare the new card (the one the user is going to predict) to the previous card. You can't just use one variable, you need two so you can com "pair". Generally, you assign the current item to the variable that holds the last item at the end of the loop.

So, what is deck? Probably just a plain old Perl array. But, what is a card? It could be a simple scalar or it could be a more complicated object. One advantage of going the OO route is using overload to handle the comparison of cards:

... if this_card > last_card ...
At any rate, no matter how you decide to represent a card, a deck is going to be an array of cards, and we need two methods to operate on this deck: shuffle() and pull(). Well, i'm lazy. I am not going to write a shuffle routine, when our pals Fisher and Yates have already written one that blows away anything i could write. Also, i know of two CPAN modules that already have the Fisher-Yates shuffle implemented: List::Util and Algorithm::Numerical::Shuffle. That takes care of shuffle()

What about pull()? Well, all that does is remove the top card. Perl has two built-in function to remove a single element (ok, so it's really three) - shift and pop. As long as you pick one and stick with it, it doesn't really matter - cards can be represented by a queue just as easily as a stack, it depends upon what game you are playing. The important thing is to remain consistent, so let's pick pop since it's shorter.

And what about prompt()? It will probably look something like:

sub prompt:
   ask user to enter H or L
   read in input
   chomp off newline
   uppercase input
   default input to H unless it is H or L
   return input
end sub

Back to the cards object. How do we program the hierarchy? It's obvious that a 9 is greater than a 2, but is a Q higher or lower than a K? If use array indices as precedence, we get a nice solution:
my @card_precedence = ('A',2..10,'J','Q','K');

# we will also need suites
my @suite_precedence = qw(clubs diamonds hearts spades);
What we really need is one array that stores some simple numerical value for ease of comparison. And then we will probably need a hash to map those values to labels ... but, the hour is growing late, and surely there is a CPAN module that could handle all of this ... Games::Cards perhaps?

(update) WARNING: SPOILERS! (click and cheat)

(note that the update is for the warning, not the code within - i want to give a better warning, but i didn't want to invalidate castaway's reply. castaway++ please read this before you click vote, eh?)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Pseduo code planning by jeffa
in thread Pseduo code planning by sulfericacid

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.