From martin_jacobs at optusnet.com.au Thu Sep 6 04:36:29 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Thu, 6 Sep 2007 21:36:29 +1000 Subject: [Brisbane-pm] Times and Dates Message-ID: <46CFA42D-18AD-4862-8F6E-B62557509BE1@optusnet.com.au> Hi Perlmongers, Here's a tricky one to do with times and dates. I'm trying to generate a timeseries. The start and end time are user- defined, as is the timestep interval. So, if I start at 06/01/1990 00:00:00, and end at 06/01/1990 00:12:00, and specify a timestep of 6 minutes, I will get a timeseries like this... 06/01/1990 00:00:00 06/01/1990 00:06:00 06/01/1990 00:12:00 I will also be reading historic rainfall data, and applying the amount of rainfall to each timestep. This requires that I read and write calendar date data in the human- friendly long format 01/01/1900 00:00:00, and do functions in terms of seconds since the epoch. The sub for interpreting human-friendly time-date data into computer friendly seconds-since-epoch is as follows... sub Calendar_date_string_to_timevalue { #Sub version 1.0 #This sub converts a string to a time value #The format of the string is DD/MM/YYYY hh:mm:ss, e.g. 25/02/1990 23:48:00 #The sub parses the string, then uses timegm to calculate its value in terms of seconds since the Epoch my (%arg) = @_; my $t = $arg{arg1}; my ($mday, $mon, $year, $hour, $min, $sec) = $$t =~ /(\d+)/g; $$t = timegm $sec, $min, $hour, $mday, $mon - 1, $year - 1900; } I'm using timegm, because the timesteps must be mathematically consequential (every timestep must occur after the preceding timestep). There are other functions, but some do corrections for daylight savings etc, which I don't want. My problem is that the output goes wrong for dates before 01/Jan/1970 00:00:00 (I think, when timevalue in seconds-since-epoch is 0). Some of my timeseries may run to 1900, or even earlier, but the sub above refuses to generate a consequential series (1901, for example, gets interpreted as 2001). BTW, I'm using Mac OSX, but the program I'm writing needs to run on any operating system. Thanks in advance for any help... Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070906/56580942/attachment.html From pjf at perltraining.com.au Thu Sep 6 06:23:58 2007 From: pjf at perltraining.com.au (Paul Fenwick) Date: Thu, 06 Sep 2007 23:23:58 +1000 Subject: [Brisbane-pm] Times and Dates In-Reply-To: <46CFA42D-18AD-4862-8F6E-B62557509BE1@optusnet.com.au> References: <46CFA42D-18AD-4862-8F6E-B62557509BE1@optusnet.com.au> Message-ID: <46DFFF6E.1000503@perltraining.com.au> G'day Martin, Martin Jacobs wrote: [snip] > My problem is that the output goes wrong for dates before 01/Jan/1970 > 00:00:00 (I think, when timevalue in seconds-since-epoch is 0). Some of > my timeseries may run to 1900, or even earlier, but the sub above > refuses to generate a consequential series (1901, for example, gets > interpreted as 2001). You haven't mentioned *which* timegm() you're using. There are at least two floating around. One you may gain using: use POSIX qw(timegm); and has its roots in BSD. The other you'd obtain with: use Time::Local qw(timegm); and is a pure perl implementation. As a first try I'd start by seeing if the other implementation from what you're using gives you more joy. Be aware that the POSIX version may be implemented differently on different systems. Cheerio, Paul -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From hey.you at mac.com Thu Sep 6 13:01:15 2007 From: hey.you at mac.com (Tony Obermeit) Date: Fri, 7 Sep 2007 06:01:15 +1000 Subject: [Brisbane-pm] Calling java method from a perl program Message-ID: I need to call a static java method (no java object instantiation required) from a perl script. Based on my googling of the topic, it seems there are a number of ways to do this. The java code is compiled and cannot be embedded within the perl script (so Inline::Java isn't appropriate).... Any suggestions as to the pros / cons of the various options? Thanks Tony From jarich at perltraining.com.au Thu Sep 6 19:02:13 2007 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Fri, 07 Sep 2007 12:02:13 +1000 Subject: [Brisbane-pm] Times and Dates In-Reply-To: <46CFA42D-18AD-4862-8F6E-B62557509BE1@optusnet.com.au> References: <46CFA42D-18AD-4862-8F6E-B62557509BE1@optusnet.com.au> Message-ID: <46E0B125.3020307@perltraining.com.au> Martin Jacobs wrote: > Hi Perlmongers, > > Here's a tricky one to do with times and dates. > > I'm trying to generate a timeseries. The start and end time are > user-defined, as is the timestep interval. So, if I start at 06/01/1990 > 00:00:00, and end at 06/01/1990 00:12:00, and specify a timestep of 6 > minutes, I will get a timeseries like this... > > 06/01/1990 00:00:00 > 06/01/1990 00:06:00 > 06/01/1990 00:12:00 In some ways it's overkill, but you may find it useful to use the DataTime module from CPAN to handle your dates. This then allows you to create a date object, add your increments easily (correctly handling leap years etc) and compare that to see if you've over-stepped your final date. You can find it here: http://search.cpan.org/perldoc?DateTime It is a large module that takes up a fair amount of memory. But it gets it right, including leap seconds, missing days centuries ago etc. All the best, Jacinta From robertl at apnic.net Tue Sep 11 00:42:16 2007 From: robertl at apnic.net (Robert Loomans) Date: Tue, 11 Sep 2007 17:42:16 +1000 Subject: [Brisbane-pm] Calling java method from a perl program In-Reply-To: References: Message-ID: <46E646D8.3080602@apnic.net> Tony Obermeit wrote: > I need to call a static java method (no java object instantiation > required) from a perl script. Based on my googling of the topic, it > seems there are a number of ways to do this. The java code is > compiled and cannot be embedded within the perl script (so > Inline::Java isn't appropriate).... I don't believe that only having a class file excludes Inline::Java. You can either tell Inline::Java to study the enclosing class: use Inline ( Java => 'STUDY', STUDY => ['your.class.name.here'], AUTOSTUDY => 1, ); your::class::name::here::method_name(args); ...or you can write your own wrapper code using Inline::Java that calls the method and call the wrapper from Perl. > Any suggestions as to the pros / cons of the various options? When I had to do this, we weren't able to get Inline::Java to work (proprietary Corba client libraries that needed to override built in classes.... ick) so we wrote a small server that listened on a TCP socket and accepted commands (eg, "provision 123.123.4.5 username password you_are_an_eggbeater")... but don't go there if Inline::Java works it's clunky and fragile. Another thought: you could use XMLRPC... but that might be over-kill :) Rob -- Robert Loomans Email: robertl at apnic.net Senior Programmer/Analyst, APNIC Phone: +61 7 3858 3100 http://www.apnic.net Fax: +61 7 3858 3199 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3818 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070911/5d20daf7/attachment.bin From martin_jacobs at optusnet.com.au Tue Sep 18 02:02:17 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Tue, 18 Sep 2007 19:02:17 +1000 Subject: [Brisbane-pm] Lost in OSX Message-ID: Hi PerlMongers, Do any of you work in Mac OS X? I've got some pretty basic questions, such as... 1 I thought I installed Perl 5.8.8 from ActiveState, but when I type perl -v in terminal it says... This is perl, v5.8.6 built for darwin-thread-multi-2level (with 3 registered patches, see perl -V for more detail) What gives? 2 How do I install modules, in particular DateTime? 3 I can't find the Perl Package Manager on my system. Nor can my launcher, or spotlight. 4 I've got a workaround for this, but how do I tell Mac OS X to open a .pl file with Perl? At present I'm running it in terminal with a perl perrmoss.pl command. Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070918/66b8002e/attachment.html From stephen at sydney.pm.org Tue Sep 18 03:16:50 2007 From: stephen at sydney.pm.org (Stephen Steneker) Date: Tue, 18 Sep 2007 20:16:50 +1000 Subject: [Brisbane-pm] Lost in OSX In-Reply-To: References: Message-ID: > Do any of you work in Mac OS X? Hi Martin, I work in Sydney, but I use OS X ;-). > I've got some pretty basic questions, such as... > > 1 I thought I installed Perl 5.8.8 from ActiveState, but when I > type perl -v in terminal it says... > > This is perl, v5.8.6 built for darwin-thread-multi-2level > (with 3 registered patches, see perl -V for more detail) > > What gives? This is the Apple-installed Perl. I'd recommend using it, unless you have a specific inclination for building your own version of perl. In my experience, building your own perl is generally a less hassle-some choice than using ActiveState because at some point you'll want to install newer modules than are available via their ppm repositories. I prefer to use the default perl and CPAN tools, which work just fine. > 2 How do I install modules, in particular DateTime? # start by running Applications => Utilities => Terminal sudo perl -MCPAN -e shell install DateTime ... for more info, check out the CPAN docs at: http://search.cpan.org/dist/CPAN/lib/CPAN.pm > 3 I can't find the Perl Package Manager on my system. Nor can my > launcher, or spotlight. Sounds like ActiveState Perl either isn't installed, or isn't in your path. Either way you'll have much more luck installing current versions of modules via the standard CPAN shell. > 4 I've got a workaround for this, but how do I tell Mac OS X to > open a .pl file with Perl? At present I'm running it in terminal > with a perl perrmoss.pl command. There are a few options, depending on what you're after: Easiest to explain if you start from a Terminal window. 1) Would assume your myfile.pl looks something like: #!/usr/bin/env perl use strict; use warnings; # ==> all the real stuff happens here (the important part here is having an initial #! line) 2) make the file executable chmod +x myfile.pl 3) create the file association, if you haven't already # open a Finder window in the current directory open . # right-click on myfile.pl # choose "Open With", then "Other..." from the right-click context menu # browse to Applications => Utilitites # change the "Enable" selection from "Recommended Applications" to "All applications" # check the "Always Open With" checkbox # double-click on "Terminal" 4) double-click on myfile.pl from Finder and it should now run OR i) Download and install the very handy Platypus app, which can be used to make a quick OS X app around your .pl script: http://www.sveinbjorn.org/platypus Hope that helps get you on the right track. For perl hints, you might want to have a look (or try posting) on http://perlmonks.org/. Cheers, Stephen