Solved

parsing

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl script help 12 105
Question about @INC variable in perl 1 65
How to search multiple patterms in a file with perl? 4 82
Perl File::Find alternative 1 79
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

828 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