Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi.

I've got a script that calls another perl file (thru a require) and executes some subroutines. It needs to pass along some variables, and yet the code doesn't seem to work...

When calling the subroutine...

$basic = 123456789;

&textfield('mls','20',$basic);


And the subroutine's code...

sub textfield($name,$size,$value) {
print qq(<input type="text" name="$name" size="$size" value="$value">);
}


Now, the problem is that the subroutine doesn't get any values for those three variables. Why??

Please help.

Thanks,
Ralph.

Replies are listed 'Best First'.
Re: Problem with subroutines
by Anonymous Monk on May 04, 2002 at 17:31 UTC
    Perl doesn't have named parameters for subroutines in the manner you are attempting. You need to grab your parameters from the @_ array within the subroutine definition.

    sub textfield { my($name, $size, $value) = @_; print qq(<input type="text" name="$name" size="$size" value="$value +">); }

    What you have done is provided a malformed prototype, which perl would have told you about if you hadn't also disabled prototypes on your subroutine call by using the & prefix in the call.