On Fri, Jun 29, 2001 at 06:04:33PM -0400, Wang, Lanbo wrote:
> #!/usr/local/bin/perl

This is your first mistake.  You forgot -w and use strict; always use both
when debugging code.  It wouldn't have helped you here, but I guarantee you
it will in the future.  So:

  #!/usr/local/bin/perl -w

  use strict;

 
> sub card{
> 
>   my %card_map;
>   my ($num)=@_;
>  @card_map{1..9}= qw(one two three four five six seven eight nine);
>   if ($card_map{$num}) {
>      $card_map{$num};
>   } else {
>       $num;
>   }
>  }
>
> while (<>) {
>   chomp;
>   print "card  of $_ is:" &card($_), "\n";

Here's your problem, you forgot a comma after the first argument to print. 
This is being evaluated as (in the case of "7" being input):

    print "card  of 7 is:" & "seven", "\n";

& is a bitwise operator, in this instance operating on strings. "card  of 7
is" & "seven" results in "card".

What you should be doing is, of course:

    print "card of $_ is", card($_), "\n":

The & is unnecessary.


> }


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to