CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Not printing the parameter inside the sub

 



datlaravi
Deleted

May 2, 2001, 8:56 AM

Post #1 of 3 (658 views)
Not printing the parameter inside the sub Can't Post

Hi,
I was just printing the paramter inside the subroutine. It is not printing.

Can you help me with this sample code.

print "Enter a number from 1 to 5: \n";

chomp($number = <STDIN>);

&cardmap($number);


sub cardmap {

my  rd;

my $num = @_;

print "Number is $num\n"; (printing 1 no matter what number i enter)



 rd = (

"1" => "one",
"2" => "TWO",
"3" => "THREE",
"4" => "FOUR",
"5" => "FIVE");



if($card{$num}) {

return $card{$num};

}

else {

return $num;

}

}

print "card of $number is", &cardmap($number), "\n";
Thanks



japhy
Enthusiast

May 2, 2001, 10:38 AM

Post #2 of 3 (657 views)
Re: Not printing the parameter inside the sub [In reply to] Can't Post

You're assigning an array to a scalar:


Code
my $x = @_;

That puts the LENGTH of @_ into $x. You want to do:


Code
my $x = shift; 
# or
my $x = $_[0];
# or
my ($x) = @_;

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


datlaravi
Deleted

May 2, 2001, 11:20 AM

Post #3 of 3 (656 views)
Re: Not printing the parameter inside the sub [In reply to] Can't Post

Thanks Japhy. NOw i understood what @_ is


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives