This is the simple data file parser I wrote for my school.
The Format is (yes this is rigid and not very nice)
Title
Page Name
Output file name
BGColor
FGColor
Number of links that need to be created
Data
I have many, many links to parse, so this was my quick fix.
I want to write this as a true parsed language, but for now
this is all I need
--LiteStar
(Stefan Edwards)
#!/usr/bin/perl
use strict;
my ($count, $title, $outname, $bgcolor, $fgcolor,$line, $pgname);
my ($link_name, $link_ref);
die "Need Data File!\n" unless $ARGV[0];
open(FDIN,"<$ARGV[0]") or die "Cannot open file ".$ARGV[0]."\n";
chomp($title = <FDIN>); print "title => $title\n";
chomp($pgname = <FDIN>); print "Page name => $pgname\n";
chomp($outname = <FDIN>); print "output file => $outname\n";
chomp($bgcolor = <FDIN>); print "bgcolor => $bgcolor\n";
chomp($fgcolor = <FDIN>); print "fgcolor => $fgcolor\n";
chomp($count = <FDIN>); print "number of links => $count\n";
open(FDOUT,">$outname") or die "Could not create file ".$outname."\n";
print FDOUT <<EOD;
<html><head><title>$title</title></head>
<body
BGCOLOR=$bgcolor
TEXT=$fgcolor>
<h3>$pgname</h3>
<p>
EOD
$count++;
for(;$count > 0; $count--)
{
chomp($line = <FDIN>);
if($line =~ /__END__/)
{
print "All Finished, Cleaning up.";
last;
}
($link_name,$link_ref) = split(/,/,$line);
print "Link Name: ".$link_name."\n";
print "Link Reference: ".$link_ref."\n";
print FDOUT "<u><a href=$link_ref>$link_name</a></u>\n";
}
close(FDIN);
print FDOUT << "OFF";
</p></body></html>
OFF
close(FDOUT);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.