in reply to Custom Module question
While this doesn't directly address your question, I notice that you seem to be mixing array/list syntax with scale syntax. Something prefixed with an '@' is an array. Sets of things in parantheses are often lists. Scalars, like a simple string, are prefixed with '$' (note that the individual elements of an array are scalars, so to refer to the first element of an array you use $arrname[0]). I suspect you want something like:
my $name = ''; printname($name); sub printname { my $name = shift; print "Hello, $name\n"; }
I've used shift to remove the 1st element of the subroutine arguments array and put it into $name. You could also use my $name = $_[0]. Use my for lexical scoping for the variable $name, that way, while there may be many scalars named $name, the one in the subroutine is distinct from any others. If you don't scope your variables wisely, your progams can quickly become unmaintainable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Custom Module question
by GrandFather (Saint) on Dec 03, 2014 at 23:00 UTC |