Brad Baxter wrote:
> On Jun 14, 10:22 pm, [EMAIL PROTECTED] (Mathew Snyder) wrote:
>> I fixed all of the bugs save one. I can't access any of my subroutines
>> without
>> explicitly using it with dates_emails::subroutine. I was under the
>> impression
>> that if I was exporting them all from the module, the subroutine would be
>> found
>> regardless.
>>
>> package dates_emails;
>> require Exporter;
>> use strict;
>>
>> our @ISA = qw(Exporter);
>> our @EXPORT = qw(startDate, endDate, searchStart, searchEnd);
>> our @EXPORT_OK = qw($emailTo, $emailFrom, $emailBcc);
>> our %EXPORT_TAGS = {
>> dates => [qw(startDate, endDate, searchStart, searchEnd)],
>> emails => [qw($emailTo, $emailFrom, $emailBcc)],
>> };
>> our $VERSION = '1';
>>
>> It doesn't even work with 'use dates_emails("dates");'. I get an error that
>> dates is not an exported subroutine. I don't understand what I'm not doing
>> right as I've got the %EXPORT_TAGS hash set up, I've got the @EXPORTS array
>> set
>> up. I've got this in my opening block:
>> use lib '/usr/local/bin/lib/';
>> use dates_emails;
>
>> use strict;
>
> add:
>
> use warnings;
>
> ...
> Possible attempt to separate words with commas at dates_emails.pm line
> 6.
> Possible attempt to separate words with commas at dates_emails.pm line
> 7.
> Possible attempt to separate words with commas at dates_emails.pm line
> 9.
> Possible attempt to separate words with commas at dates_emails.pm line
> 10.
> Reference found where even-sized list expected at dates_emails.pm line
> 8.
>
> That may not be your whole problem, but it might get you a little
> farther.
>
> --
> Brad
>
>
I need to revisit this.
I've broken things down a bit and separated the email addresses from the date
subs and now have two files under /usr/local/bin/lib/Reports: Dates.pm and
Emails.pm.
*Dates.pm:*
package Dates;
require Exporter;
use strict;
use warnings;
our @ISA = qw(Exporter);
our @EXPORT = qw(startDate endDate searchStart searchEnd);
our $VERSION = '1';
# Declare our global variables
my (@date, @days, @months, @years, @searchDate);
my $time = time();
our (@searchDate, $startDate, $endDate, $searchStart, $searchEnd);
sub getDates {
for (1 .. 7) {
$time -= 24*60*60;
@date = (localtime($time))[3 .. 5];
push @days, (sprintf '%02d', $date[0]);
push @months,(sprintf '%02d',$date[1] + 1);
push @years, $date[2] + 1900;
return;
}
}
sub searchDate {
getDates();
push @searchDate, join "-", ($date[2] + 1900), (sprintf '%02d',$date[1]
+ 1),
(sprintf '%02d', $date[0]);
return [EMAIL PROTECTED];
}
sub startDate {
getDates();
$startDate = join "-", $months[$#months], $days[$#days],
$years[$#years];
return $startDate;
}
sub endDate {
getDates();
$endDate = join "-", $months[0], $days[0], $years[0];
return $endDate;
}
sub searchStart {
getDates();
$searchStart = join "-", $years[$#years], $months[$#months],
$days[$#days];
return $searchStart;
}
sub searchEnd {
getDates();
$searchEnd = join "-", $years[0], $months[0], $days[0];
return $searchEnd;
}
return 1;
The simple thing I'm trying to do to test all of this is:
#!/usr/bin/perl
###################################
# Title: module_test.pl
# Author: Mathew Snyder
# Reliease: 0.1
# Date: June 13, 2007
###################################
use warnings;
use strict;
use lib "/usr/local/bin/lib";
use Reports::Dates;
my $today = startDate();
print $today . "\n";
Doing things this way gives me an error telling me that &main::startDate isn't
defined. However, if I use 'my $today = Dates::startDate;' it works. I'm
confused since I told it to 'use Reports::Dates;'.
Anyone have any insight on why this isn't working the way I've been told it
should?
Thanks,
Mathew
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/