Solved

parsing

Posted on 1998-12-21
2
165 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
2 Comments
 

Author Comment

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

Accepted Solution

by:
b2pi earned 200 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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 …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now