in reply to Sub Routine Problem
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.
|
|---|