koolgirl,

This is a good opportunity to learn unit testing with Test::More et.al. :

# 718965.pm use strict; use warnings; my @card_map = qw(zero one two three four five six seven eight nine); sub card { my $num = shift; my $negative = "negative"; if ($card_map[$num]) { return $card_map[$num]; } else { return $num; } if ($num > 0) { return $num = -$num; } if ($card_map[$num]) { return $negative . $card_map[$num]; } else { return $negative . $num; } } use Test::More; plan tests => 3; is(card(5), 'five', 'Expect card(5) to return "five"'); is(card(6), 'six', 'Expect card(6) to return "six"'); is(card(-6), 'negative six', 'Expect card(-6) to return "negative six" +'); __END__ $ prove 718965.pm 718965....NOK 3 # Failed test 'Expect card(-6) to return "negative six"' # at 718965.pm line 32. # got: 'four' # expected: 'negative six' # Looks like you failed 1 test of 3. 718965....dubious Test returned status 1 (wstat 256, 0x100) DIED. FAILED test 3 Failed 1/3 tests, 66.67% okay Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- 718965.pm 1 256 3 1 33.33% 3 Failed 1/1 test scripts, 0.00% okay. 1/3 subtests failed, 66.67% okay.
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

In reply to Re: Sub Routine Problem by andreas1234567
in thread Sub Routine Problem by koolgirl

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.