?
Solved

parsing

Posted on 1998-12-21
2
Medium Priority
?
203 Views
Last Modified: 2010-03-05
I have a bunch of files in a directory
 eg. Filename120398101203.doc
     Filename121098150934.doc
     Filenamemmddyyhhmmss.doc
     ....etc

I need to write a program that can automatically grab the a filename and parse it into the correct format.

eg.   #      DATE           TIME
      1      12/03/98       10:12:03
      2      12/10/98       15:09:34
      3      mm/dd/yy       hh:mm:ss

Then spit this information onto an HTML page.  
0
Comment
Question by:dmx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:dmx
ID: 1207068
Edited text of question
0
 
LVL 5

Accepted Solution

by:
b2pi earned 600 total points
ID: 1207069
I assume you want to use the filename, rather than it's time stamp.. This should show you how....

#!/usr/bin/perl -w

use strict;

$| = 1;
$base = "/home/asdf"; # or wherever the files are


print "Content-type: text/html\n\n";
print "<HTML>\n";
opendir(DIR,$base) || die "Unable to open dir $base: $!\n";

my(@Files) = grep {-f "$base/$_"} readdir(DIR);
my($i) = 1;
my($date, $time);

print <<EOText;
<br>
<P ALIGN = "CENTER"><CENTER>
<TABLE BORDER CELLSPACING=1 BORDERCOLOR="#000000">
<TR>
<TD BGCOLOR="#000000"><P ALIGN="CENTER"><B>#</B></TD>
<TD BGCOLOR="#000000"><P ALIGN="CENTER"><B>Date</B></TD>
<TD BGCOLOR="#000000"><P ALIGN="CENTER"><B>Time</B></TD>
</TR>
EOText

foreach (@files) {
    m/^(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})/;
   $date = "$1/$2/$3";
   $time = "$4:$5:$6";
   print <<EOText;
<TR>
<TD><P ALIGN="CENTER">$i</TD>
<TD><P ALIGN="CENTER">$date</TD>
<TD><P ALIGN="CENTER">$time</TD>
</TR>

EOText;
}

print "</TABLE></CENTER></P></HTML>";
#------- End
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question