in reply to Returning Values from Subroutines
Hey there. I'm not entirely sure why it's not working as is as I am but a novice, but the following works for me:
As far as the original not working, will the initial sub ("main") even run without a call to it? I tried running it with a call for it and got an error. Also, in the the "add" sub, you are returning $answer, but it was never assigned a value in the sub.
Anyone else want to chime in? I'd like to hear more on this one as well.
mb++
was hoping to get first return, but was beat out by six minutes... curses!
#!/usr/local/bin/perl my $answer = &add(1,2); print $answer; sub add{ return $result = ($_[0] + $_[1]); }
As far as the original not working, will the initial sub ("main") even run without a call to it? I tried running it with a call for it and got an error. Also, in the the "add" sub, you are returning $answer, but it was never assigned a value in the sub.
Anyone else want to chime in? I'd like to hear more on this one as well.
mb++
was hoping to get first return, but was beat out by six minutes... curses!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Returning Values from Subroutines
by mojobozo (Monk) on Sep 06, 2002 at 15:05 UTC | |
by mojobozo (Monk) on Sep 06, 2002 at 16:38 UTC | |
by zigdon (Deacon) on Sep 06, 2002 at 17:48 UTC | |
by blokhead (Monsignor) on Sep 06, 2002 at 17:33 UTC | |
by Arien (Pilgrim) on Sep 06, 2002 at 22:22 UTC |
In Section
Seekers of Perl Wisdom