Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse data, convert time format & write to temp file

Status
Not open for further replies.

ITadvice

IS-IT--Management
Jul 22, 2008
38
US
I have tab delimited text files that have date/time in excel serial format (34567.6256345). I want to collect the data from the 1st, 4th & 8th columns, convert them to normal time (yymmdd hh:mm:ss:ss) and then write the new format to a temporary file. I'm familar with how to parse data, create temp files and change the format. My problem is that I'm not sure how to blend all three together. Any suggestions or advice?
 
yeah.. post some code :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Here is the code I have so far:


open(FILE, "<text_file.txt") or return;
$fh = IO::File->new_tmpfile or die "Unable to make new temp file: $!";
$fh->autoflush(1);
while (my $line = <FILE>) {
my $datetime = DateTime::Format::Excel->parse_datetime($line);
print $datetime->ymd;
print $datetime->hms;
seek ($fh, 0, 0) or die "Seek: $!";
print $fh "[ (split(/\t/, $line))[0,3,7] ]";
return ($fh);
}
print "Temp file contains: \n", <$fh>;
 
ahhh... you are already using the module. :)

change this line:

Code:
print $fh "[ (split(/\t/, $line))[0,3,7] ]";

change to:

Code:
print $fh (split(/\t/, $line))[0,3,7],"\n";

or if you really want the brackets in there:

Code:
print $fh '[', (split(/\t/, $line))[0,3,7], ']',"\n";

perl does not execute functions inside of double-quoted strings, at least not the way you wrote it, and its not necessary anyway.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
When I run my program, this line:

Code:
print "Temp file contains: \n", <$fh>;

prints out this: "Temp file contains: IO::File=GLOB(0x86e...)"

What does this mean? Is the information not being put in the temp file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top