in reply to Using a subroutine as a module
Referring to a variable inside a package is not recommended. You could do the following instead -package MyValidate; # use package to declare a module our $val; sub val_time { $val = shift; $val = ($val =~ /^(\d{2}):(\d{2}) (am|pm)$/) ? "$1:$2 $3" : 1; } 1;
package MyValidate; # use package to declare a module sub val_time { my $val = shift; $val = ($val =~ /^(\d{2}):(\d{2}) (am|pm)$/) ? "$1:$2 $3" : 1; return $val; # yes this is not necessary but it clarifies my inten +sion } 1;
|
|---|