I have a template I am trying to build that iterates through a list of dcrs and sorts them by date. I built this using a combination of some reference files I have as well as searching through devnet posts.
I am having an issue with my output (it prints the file name in front of each value)
I am also wondering if this is the most efficient way to do this. I only want to output info from the 3 most recent dcrs (by $PubDate) in the directory. I must admit I am still a beginner with Perl so it is probably not the best you have ever seen, but here is the code.
[HTML] use TeamSite::XMLparser;
# init vars
my $i;
my $out;
# Directory To Find DCR Records To Loop In
my $dir = "Y:\\default\\main\\Project\\WORKAREA\\content\\templatedata\\Project\\NewsArticle\\data\\";
opendir(THISDIR, $dir) or die("$! - Cannot Open DIR");
my
@allfiles = grep !/^\.\.?$/, readdir THISDIR; closedir THISDIR;
foreach my $file (
@allfiles) {
open(DCR, "$dir$file") or die("$! - Cannot open DCR");
local $/ =undef;
my $xml = ;
close DCR;
my $parser = TeamSite::XMLparser->new();
my $rootnode = $parser->parse($xml);
my $Headline = $rootnode->value('pageTitle');
my $Intro = $rootnode->value('metadata.description');
my $PubDate = $rootnode->value('metadata.pubDate');
my $dcr_count = scalar(
@allfiles);
opendir(THISDIR, $dir) or die("$! - Cannot Open $dir");
@allfiles = grep !/^\.\.?$/, readdir THISDIR;
closedir THISDIR;
# create the sort array
for($i =0;$i<
@allfiles;$i++){
$sortItems[$i]=$PubDate.$Headline.$Intro.$file;
}
@sortItems =sort@allfiles;
for ($i = 0; $i < 3; $i++) {
$out . = <
$sortItems[$i].$Headline: $sortItems[$i].$Intro
EOM
}
}
iwpt_output($out);
[/HTML] [url="
http://devnet.interwoven.com/forums_vb/$sortItems[$i].$file"][/url]