Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / December 2006



Tip: Looking for answers? Try searching our database.

Conflict with Time::Local and Time::localtime

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Barto - 31 Dec 2006 09:19 GMT
I have a Perl program that gets the date of a file using '*ctime*' from
"*use Time::localtime;*" But this program must also convert an Epoch
time to a date and time using '*localtime*' from "*use Time::Local;*".
The problem is it appears that only one of these modules can be used in
a single program. Not both since a *localtime* subroutine exist as the
same name in both modules.  How can I support using both modules in the
same program?. Here are the snippits:

#!/usr/bin/perl
*use Time:localtime;
use Time:Local;
*
*#needs Time::Local........*
sub convertEPOCHtime ($) {
   my $time = $_[0];
   my ($seconds, $minutes, $hours, $day_of_month, $month, $year, $wday,
$yday, $isdst) = *localtime ($time)*;
   $year += 1900;
   my @themonths =
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
   my @weekdays = ("xxx", "Sat", "Sun", "Mon", "Tue", "Wed", "Thr",
"Fri", );
   if ($hours < 10) {
       $hours = '0' . "$hours";
   }
   my $datestring = "$weekdays[$wday] $themonths[$month] $day_of_month
${hours}:${minutes} $year";
   return ($datestring);
}

*# needs Time::localtime........*
sub FILEdate ($) {
   my $filename = $_[0];
   my $as_of_date = *ctime(stat("$filename")->mtime)*;
   return ($as_of_date);
}

Signature

------------------------------------------------------------------------
*Michael Barto*
Software Architect

    LogiQwest Circle
LogiQwest Inc.
16458 Bolsa Chica Street, # 15
Huntington Beach, CA  92649
http://www.logiqwest.com/

           mbarto@logiqwest.com <mailto:mbarto@logiqwest.com>
Tel:  714 377 3705
Fax: 714 840 3937
Cell: 714 883 1949

*'tis a gift to be simple*
------------------------------------------------------------------------
This e-mail may contain LogiQwest proprietary information and should be
treated as confidential.

Sherm Pendley - 31 Dec 2006 18:04 GMT
> I have a Perl program that gets the date of a file using 'ctime'  
> from "use Time::localtime;" But this program must also convert an  
[quoted text clipped - 8 lines]
> use Time:localtime;
> use Time:Local;

You're importing everything by default. Instead, only import the  
specific functions you need from each module:

    #!/usr/bin/perl

    use Time::localtime qw(ctime);
    use Time::Local qw(localtime);

Have a look at "perldoc Exporter" for more, especially the section  
titled "How to Import".

sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.