Hello,

I am new to perl and having trouble with a script I wrote to publish some data in an 
rss format. The script works great from the command prompt but dies when I use input 
from a web form. The error is "No such file or directory" for my template. The file is 
there and I have no trouble with this from the command prompt. The directory the 
script resides in has write permissions on for anon web users. 

Here is the script - I made a notation where I am getting the error. And since I am a 
newbie any general perl/coding tips you all have I would be grateful to hear. Thanks 
in advance for your help!

#########################
# includes
#########################
use strict;
use warnings;
use CGI qw(:standard);
use XML::RSS;

#########################
# vars
#########################
my $dateStamp;
# my $title = "Title here"; # test value - uncomment to use
# my $desc = "Desc here"; # test value - uncomment to use
# my $full = "Full test here"; # test value - uncomment to use
# my $newName = "5142002222232rss.asp"; #test value - uncomment to use
        
#########################
# make a date stamp
#########################
(my $sec, my $min, my $hour, my $mday, my $mon, my $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 = "$mon$mday$year$hour$min$sec";             # datestamp to identify the 
entry

&getInput ($dateStamp); # call the sub to get the rss input
undef &getInput;

&writeRss ($newName);   # call sub to write the rss file
undef &writeRss;

undef &main;

#########################
#  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 = "rss_outtemplate.htm";
        my $tempHTML ='';
        my $fullOutfile = "rss.asp";
        my $fileTag = shift;
        my $newName;
        
        #########################
        # format the form data using a template
        #########################
        open(FILEFULL, $template) or die ("Couldn't open template file - $template - 
$!\n"); # <-- script dies right here, but only from web form.
        while (<FILEFULL>) {
                        $tempHTML =~s /xTitle/$title/g;
                        $tempHTML =~s /xDesc/$desc/g;
                        $tempHTML =~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 $fullOutfile - $!\n");
        print FILESTOR $tempHTML;
        close FILESTOR or die ("Couldn't close  $fullOutfile - $!\n");
        
        #########################
        # rename the dump file with datestamp
        #########################
        $newName = $fileTag. "rss.asp";
        rename $fullOutfile, $newName or die ("Couldn't rename rss out file - 
$fullOutfile - $!\n");
        return $newName;
}

#########################
#  sub to write the rss file
#########################
sub writeRss ($newName) {
my $rss = new XML::RSS (version => '1.0');
my $rss_output = "rss.xml";
my $rss_link= shift;

        $rss->parsefile($rss_output);
        pop(@{$rss->{'items'}}) if (@{$rss->{'items'}} == 15);
        $rss->add_item(title => $title,
                       link  => "path/to/my/site/here/$rss_link",
                                   description => $desc,
                       mode  => 'insert'
                       );
        $rss->save($rss_output);

}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to