Solved

parsing

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

740 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