My Dearest Monks. A while ago, I had written my first sub routine, had some malfunctions, asked for your help, learned some valuable lessons and have since moved on. Well, I am now trying to expand that same routine, and it isn't working correctly, and lo and behold...I need your expertise yet again. This is the sub routine:
#!usr/bin/perl use strict; my $guess; print "Enter your number...\n"; chomp($guess = <STDIN>); print "card of $guess is ", &card($guess), "\n"; print "\nRockstar Programming Inc. All Rights Reserved\n"; ## subroutines ### sub card { my @card_map = qw(zero one two three four five six seven eight nine); my $guess; my $i = 0; our $num; our $negative = "negative"; local($num) = @_; if ($card_map[$num]) { $card_map[$num]; # return value } else { $num; # return value } # end if if ($num > 0) { $num = - $num; } # end if if ($card_map[$num]) { $negative . $card_map[$num]; # return value } else { $negative . $num; # return value } # end if } # end sub
The code works, however my output isn't what it should be. I am looking to get the cardinal name returned for each number I enter from 1 - 9, or from -9 - 0, and the same number returned for all other entries. However, the words given in my output, are not matching the numbers entered. Theoretically it should work. I think the problem is in how the input is being matched against the @, because the output is off, but it looks to me as though it shouldn't be doing this?
Any suggestions would be greatly appreciated. Also, as always, please forgive my simplicity, as I am very brand new to the programming world, and I realize my code must be elementary and border on a waste of time for most. I have spent quite a bit of time, reviewing every technique I'm using in this code, in both my llama book, the camel book and on-line docs, and I even have an almost exact example of Randall's, which I tweaked (which is basically what this mostly consists of - tweaked examples of Randall's from the llama book), and all of these say this should work. Any clue?
P.S. Thank you for your time Monks.
UPDATE: Fixed a "typo", thanks Lawliet ;)
In reply to Sub Routine Problem by koolgirl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |