in reply to Re-assign value to subroutine
or just use a variable instead of the subroutine:{ my $saved_option = 10; # default value is 10 sub options{ # were we passed a value to save for later? if (@_) { $saved_option = shift; } return $saved_option } }
By the way, your code had so many errors, it's clearly not what you were trying. It really helps if you show the exact code you are working with.my $option = 10; while (1) { print"choose 1 or 2 \n"; my $choice=(<STDIN>) or last; if ($choice == 1) { &flashcard($option); } elsif ($choice == 2) { print"enter random range\n"; my $option = (<STDIN>); } else { last } } sub flashcard { my $option = shift; my $random = int(rand($option)); # do stuff with $random }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Re-assign value to subroutine
by props (Hermit) on Nov 19, 2007 at 23:04 UTC |