People often try to overthink a problem. Since you're new to programming, you probably don't fully appreciate that simplification gives clarity. Use as few logical steps as necessary, and remove any clutter as you go along. Here's some tips:

sub card { my @card_map = qw(zero one two three four five six seven eight nine); # these aren't used, so they should be removed my $guess; my $i = 0; # there is no need for these vars to be global: our $num; our $negative = "negative"; # declare them as lexicals instead my $num; my $negative = "negative"; # declaring $num as lexical you don't need to localize: local($num) = @_; # this works here, but do you really understand what its doing? # hint: list context my ($num) = @_; # this is better my $num = $_[0]: # or this: my $num = shift @_; # commonly shortened (@_ is implicit) to: my $num = shift; # for the rest, notice how much simpler the logic # is in moritz reply above # so putting it all together: sub card{ my $num = shift; my $negative = "negative"; my @card_map = qw(zero one two three four five six seven eight nin +e); my $return_value; if ($num < 0){ $num = -$num; $return_value = $negative; } $return_value .= "$card_map[$num]"; return $return_value; } # and simplified further: sub card{ my $num = shift; my @card_map = qw(zero one two three four five six seven eight nin +e); if ($num < 0){ $num = -$num; return "negative $card_map[$num]"; } return $card_map[$num]; }

Update: corrected typo


In reply to Re: Sub Routine Problem by hangon
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.