The warning about uninitialized value is because in line 6 of the code you posted you set $name to contain nothing, and then in line 8 of the code you posted, you call printname($name). As the printname function executes, it attempts to print "Hello $name\n", where $name is empty (or undef), and this throws a warning.
Later when you call printname("John"), it actually works, because the parameter you pass in is not empty; it contains "John".
There are other issues, such as calling printname from your package main without your printname.pm module actually exporting the subroutine. But apparently your actual usage is not exactly as described, because you didn't mention that error. If you are seeing that error but simply not mentioning it, you should look at Exporter for solutions.
Additionally, you really should be using lexical variables in your subroutine that are scoped to the subroutine itself, not to the entire file: my ($name) = @_; would be a good start.
Dave
In reply to Re: Custom Module question
by davido
in thread Custom Module question
by imfaus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |