Solved

parsing

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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