Question: I'm not sure how to call another subroutine from a sub declared in a perl module. The subroutine is simply getting date information.

I have a file handle open for a log file and I want to print out some date information to this logfile, but its not printing out. I can see that it touches the file, I made the log file -rwx too.

Here is the sample subroutine in perl (Test.pm) module that I am calling:

```
sub spGetCurDateTime {
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
    my $currentDateTime = sprintf "%4d-%02d-%02d %02d:%02d:%02d",
        $year+1900, $mon+1, $mday, $hour, $min, $sec;
    return $curDateTime;
}

```

Here's part of my test code where I am trying to call the subroutine from (Test.pm)

```
use Test.pm;

#Create log
open (LOG, ">/home/dev/test.log") || die "cannot append";

sub get_alert {
   undef $/;
   open (my $QFH, "< /home/dev/test.sql") or die "error can't open this file $!";
   print LOG "Checking on status time =>", &spGetCurDateTime, "\n";
   my $sth= $dbh->prepare(<$QFH>) ||
      die ("Cannot connect to the database: ".$DBI::errstr."\n");
   $sth->execute;
   close $QFH;
   my $row = $sth->fetchrow_hashref;
   $sth->finish;
   return $row->{RESULT};
   print $row;
}

```

Answer: 
First, never say `&functionname` unless you know why you might want magic behavior. In general in Perl 5, function calls look like `functionname()` or `functionname` depending on whether you want it treated as a term (i.e. the highest level of precedence) or an operator (it is easier when you are starting out to just always use the `functionname()` form since that will do what you expect it to).

You can say

```
print LOG "Checking on status time =>", Test::spGetCurDateTime(), "\n";

```

But that can get old, so most people use the [`Exporter`](http://perldoc.perl.org/Exporter.html) module to export certain functions and variables into the namespace that said `use Test;`. You may also wish to avoid using the module name `Test`, there is already a [module with that name](http://perldoc.perl.org/Test.html).

In the file T.pm:

```
package T;

use strict;
use warnings;

use Exporter qw/import/;
our @EXPORT_OK = qw/spGetCurDateTime/;

sub spGetCurDateTime {
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
    my $currentDateTime = sprintf "%4d-%02d-%02d %02d:%02d:%02d",
        $year+1900, $mon+1, $mday, $hour, $min, $sec;
    return $currentDateTime;
}

1;

```

In the file t.pl:

```
#!/usr/bin/perl

use strict;
use warnings;

use T qw/spGetCurDateTime/;

print spGetCurDateTime(), "\n";

```
Read man perlmod. You need to put the function as an exported symbol, fully qualify it, or import it specifically...