I have written a few scripts for cron jobs on my website, but I am NO expert
I am trying to write a perl script that will read the last modified date of the .shtml files on the root of my server and update them in my sitemap_test.xm l file also in the root.
My first step was to get the script to gather and print the info I need so later I could write it to the sitemap_text .xml file.
I was able to get the .shtml file names, the modified date in the right format for the .xml file. Then open the file match the .shtml file name in the .xml file but I can't get perl to pull the next line that contains the <lastmod>.+</lastmod> that I need for the variable to write the modification date into.
Note: the sitemap_test.xm l is Windows (CRLF). Here is a link to it http://saildallas.com/sitemap_test.xml
Here is the code
[CODE=Perl]
use warnings;
use strict;
use POSIX;
# Gather the .shtml files in n array #
my @shtml_files = <*\.shtml>;
# The Sitemap file
my $filename = "sitemap_test.x ml";
foreach my $shtml_files (@shtml_files)
{
my $lastmod = strftime("%Y-%m-%dT%H:%M:%S-06:00", localtime((stat ($shtml_files))[9]));
print "\n$shtml_files \n";
print "$lastmod\n ";
open ( MYFILE, $filename) or die "Cannot open file: $!";
while (<MYFILE>)
{
my $string= $_;
#$string =~ s/\s+$//;# Strip off all trailing white spaces - tabs, spaces, new lines and returns as well.
#print "$string";
if ($string =~ m/$shtml_files/)
{
print "Found .shtml = $_";
my $nextLine = <MYFILE>;
#$nextLine =~ s/\s+$//;
print "Found lastmod = $nextLine\n";
}
#if (m/<lastmod>.+<\/lastmod>/)
#{
# print "$_";
#}
}
}
[/CODE]
Thanks in advance for any help.
I am trying to write a perl script that will read the last modified date of the .shtml files on the root of my server and update them in my sitemap_test.xm l file also in the root.
My first step was to get the script to gather and print the info I need so later I could write it to the sitemap_text .xml file.
I was able to get the .shtml file names, the modified date in the right format for the .xml file. Then open the file match the .shtml file name in the .xml file but I can't get perl to pull the next line that contains the <lastmod>.+</lastmod> that I need for the variable to write the modification date into.
Note: the sitemap_test.xm l is Windows (CRLF). Here is a link to it http://saildallas.com/sitemap_test.xml
Here is the code
[CODE=Perl]
use warnings;
use strict;
use POSIX;
# Gather the .shtml files in n array #
my @shtml_files = <*\.shtml>;
# The Sitemap file
my $filename = "sitemap_test.x ml";
foreach my $shtml_files (@shtml_files)
{
my $lastmod = strftime("%Y-%m-%dT%H:%M:%S-06:00", localtime((stat ($shtml_files))[9]));
print "\n$shtml_files \n";
print "$lastmod\n ";
open ( MYFILE, $filename) or die "Cannot open file: $!";
while (<MYFILE>)
{
my $string= $_;
#$string =~ s/\s+$//;# Strip off all trailing white spaces - tabs, spaces, new lines and returns as well.
#print "$string";
if ($string =~ m/$shtml_files/)
{
print "Found .shtml = $_";
my $nextLine = <MYFILE>;
#$nextLine =~ s/\s+$//;
print "Found lastmod = $nextLine\n";
}
#if (m/<lastmod>.+<\/lastmod>/)
#{
# print "$_";
#}
}
}
[/CODE]
Thanks in advance for any help.
Comment