Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: True Intege...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 27 of 28 Topic 16073 of 16486
Post > Topic >>

Re: True Integer, Double

by Tim Smith <reply_in_group@[EMAIL PROTECTED] > May 18, 2008 at 03:24 PM

In article <Pine.LNX.4.64.0805181327500.13853@[EMAIL PROTECTED]
>,
 Tom Anderson <twic@[EMAIL PROTECTED]
> wrote:
> > Are you *required* to use Java for this?  Your problem seems to be 
> > getting into the realm where Perl might be more convenient.  This is
the 
> > kind of thing it was designed for.
> 
> Perl was designed? I thought Larry Wall just found it growing under a
log 
> one day.

Haha, but my suggestion was serious.  For the first format he proposed, 
this is what I think he wants:

#!/usr/bin/perl
use strict;
use POSIX qw(strftime);

while (<>) {
    chomp;
    s/^\s+//;
    s/\s+$//;
    my($mmyy,$day,@[EMAIL PROTECTED]
) = split /\s+/;
    my($month,$year) = $mmyy =~ /(\d+?)(\d\d)$/;
    my $hour = 0;
    foreach my $value (@[EMAIL PROTECTED]
) {
        my $time_string = strftime "%Y-%m-%d %H:%M:%S", 0, 0, $hour,
                $day, $month-1, $year;
        print qq{<event data="$time_string" value="$value" />\n};
        $hour += 6;
    }
}

It gives this output for his sample line:

<event data="1995-12-01 00:00:00" value="38.23" />
<event data="1995-12-01 06:00:00" value="39.26" />
<event data="1995-12-01 12:00:00" value="41.10" />
<event data="1995-12-01 18:00:00" value="43.82" />
<event data="1995-12-02 00:00:00" value="47.50" />
<event data="1995-12-02 06:00:00" value="45.29" />

It deviates slightly from exactly what he asked for, in that it prints 
month and day with a leading 0 if they are less than 10, but I suspect 
that is OK.  (And if not, it can be fixed easily).  I am also assuming 
all the data is from before 2000, which seems likely.  If not, that can 
be fixed easily, but he didn't say how dates past 1999 are recorded in 
the original data.

He's going from data in a text form (flat file), to data in a text form 
(XML), so I think it arguably makes sense to treat it as much as you can 
as a text transformation, and not get into the issues he's getting into 
of integers versus floating point.  Transform the text as 
straightforwardly as possible into XML, and then, if he wants to also 
validate format, he can supply an XML schema that specifies the formats 
of the attributes and validate against that.


-- 
--Tim Smith
 




 28 Posts in Topic:
True Integer, Double
RC <raymond.chui@[EMAI  2008-05-12 10:50:14 
Re: True Integer, Double
"Kenneth P. Turvey&q  2008-05-12 15:00:58 
Re: True Integer, Double
ram@[EMAIL PROTECTED] (S  2008-05-12 15:02:32 
Re: True Integer, Double
Eric Sosman <Eric.Sosm  2008-05-12 11:10:01 
Re: True Integer, Double
RC <raymond.chui@[EMAI  2008-05-12 11:35:06 
Re: True Integer, Double
ram@[EMAIL PROTECTED] (S  2008-05-12 15:45:53 
Re: True Integer, Double
Eric Sosman <Eric.Sosm  2008-05-12 12:10:08 
Re: True Integer, Double
"John B. Matthews&qu  2008-05-12 13:54:51 
Re: True Integer, Double
Wojtek <nowhere@[EMAIL  2008-05-12 18:08:19 
Re: True Integer, Double
Mark Space <markspace@  2008-05-12 13:25:36 
Re: True Integer, Double
Eric Sosman <Eric.Sosm  2008-05-12 16:45:30 
Re: True Integer, Double
Mark Space <markspace@  2008-05-12 17:21:11 
Re: True Integer, Double
=?ISO-8859-15?Q?Arne_Vajh  2008-05-12 20:48:21 
Re: True Integer, Double
RC <raymond.chui@[EMAI  2008-05-13 10:07:35 
Re: True Integer, Double
Eric Sosman <Eric.Sosm  2008-05-13 10:46:37 
Re: True Integer, Double
Lew <lew@[EMAIL PROTEC  2008-05-13 19:39:58 
Re: True Integer, Double
Lew <lew@[EMAIL PROTEC  2008-05-13 19:39:04 
Re: True Integer, Double
=?ISO-8859-15?Q?Arne_Vajh  2008-05-14 20:13:01 
Re: True Integer, Double
Tim Smith <reply_in_gr  2008-05-17 22:21:30 
Re: True Integer, Double
=?ISO-8859-15?Q?Arne_Vajh  2008-05-12 18:41:08 
Re: True Integer, Double
"Arved Sandstrom&quo  2008-05-12 19:56:14 
Re: True Integer, Double
RedGrittyBrick <RedGri  2008-05-12 22:54:27 
Re: True Integer, Double
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-12 18:45:46 
Re: True Integer, Double
Patricia Shanahan <pat  2008-05-12 17:06:00 
Re: True Integer, Double
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-12 20:45:35 
Re: True Integer, Double
Tom Anderson <twic@[EM  2008-05-18 13:29:15 
Re: True Integer, Double
Tim Smith <reply_in_gr  2008-05-18 15:24:30 
Re: True Integer, Double
Roedy Green <see_websi  2008-05-12 20:28:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 20:52:42 CDT 2008.