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

    I prefer to use my ($name) = @_; because it scales better and it preserves @_ in case I have need to access the parameters later in the sub. Using the list form shown also provides better usage documentation by showing the parameters in much the same way they are provided by calling code.

    Perl is the programming world's equivalent of English