I am writing a rss file. Here is the full code:
#########################
# includes
#########################
use strict;
use warnings;
use CGI qw(:standard);
use XML::RSS;
#########################
# vars
#########################
my $dateStamp;
my $dirPath = "C:/Inetpub/wwwroot/mywebsite/rss/";
my $newName = '';
my $passName = '';
my $currentDate;
my $fullOutfile;
#########################
# make a date stamp
#########################
my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
$mon += 1; #this will change the month from a 0-11 format to a
+useable 1-12 format
$year += 1900; # year is number since 1900 - so we add 1900 to
+get the full year.
$dateStamp = "$year$mon$mday$hour$min"; # datestamp to identify
+ the entry
#########################
# sub to get rss input from htm form and write it to a file
#########################
sub getInput {
my $title = param('title');
my $desc = param('desc');
my $full = param('full');
my $template = $dirPath. "rss_outtemplate.htm";
my $tempHTML ='';
my $fullOutfile = "$dirPath.rss.htm";
$full =~ s/\r/<br><br>/g; # putting <br>'s in where there were cr'
+s in the input
#########################
# format the form data using a template
#########################
open(FILEFULL, $template) or die ("Couldn't open template file - $
+template - $!\n");
while (<FILEFULL>) {
s/xTitle/$title/g;
s/xDesc/$desc/g;
s/xfull/$full/g;
$tempHTML .= $_;
}
close FILEFULL or die ("Couldn't close $template - $!\n");
#########################
# write the form data with template to the dump file
#########################
open(FILESTOR,"> $fullOutfile") or die ("Couldn't open $fullOutfil
+e - $!\n");
print FILESTOR $tempHTML;
close FILESTOR or die ("Couldn't close $fullOutfile - $!\n");
return $fullOutfile
}
#########################
# rename the dump file with fileTag
#########################
sub renameFile ($$){
my $fileTag = shift;
my $fullOutfile = "$dirPath.rss.htm";
$passName = $fileTag. "rss.htm";
my $newName = $dirPath.$fileTag. "rss.htm";
rename $fullOutfile, $newName or die ("Couldn't rename rss out fil
+e - $fullOutfile - $!\n");
return $passName;
}
#########################
# sub to write the rss file
#########################
sub writeRss ($) {
my $rss = new XML::RSS (version => '1.0');
my $rss_output = "$dirPath/rss.xml";
my $title = param('title');
my $desc = param('desc');
my $rss_link = shift;
$rss_link = "http://www.mywebsite.com/rss/$rss_link";
$rss->parsefile($rss_output);
pop(@{$rss->{'items'}}) if (@{$rss->{'items'}} == 15);
$rss->add_item(title => $title,
link => $rss_link,
description => $desc,
mode => 'insert'
);
$rss->save($rss_output);
}
#########################
# wrap it all up
#########################
sub writeAfter {
print "Content-type: text/html\n\n";
print "Sucess - put something in here later ... a page to link bac
+k to the site - stuff like that.\n"
}
#########################
# call subs
#########################
getInput;
renameFile ($dateStamp, $fullOutfile);
writeRss ($passName);
writeAfter;
undef &main;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|