Monks,

With my limited and old fashioned understandings in PERL I've written this getrss plugin to my aXML system. Whilst this plugin works already, I beseech information on how to modernise and improove this code such that it passes the poetic standards of perl in 2007.

The plugin is called from within the aXML doc using the <getrss> tag in the following way:

(getrss url="http://news.bbc.co.uk/rss/newsonline_world_edition/front_ +page/rss.xml") <h3><d>title</d></h3> <p><d>description</d></p> <p><link to="<d>link</d>">Read More...</link></p> (/getrss)

The ( ) brackets indicate to the aXML parser that this tag must be run before its child tag, since it contains a link command which depends on data which would not be available if the link were run first.

The contents of the (getrss) tag is a "mask" for each item found in the rss return, and <d> represents an item of data within that item. Link is a hyperlink generator plugin.

The data within the getrss tag is handed to the getrss plugin and is referred to as $data within the plugin. The plugin builds the string $result, which is then handed back.

my $module = 'LWP::Simple'; my $return_val = $module->use; if ($return_val) { $raw_data = get($command_args->{url}); $result = ""; if ($raw_data =~ m@<channel>(.*?)</channel>@s) { $channel_data = $1; $channel_data =~ s@\[@<lftsqbrk/>@g; $channel_data =~ s@\]@<rtsqbrk/>@g; $channel_data =~ s@\(@<lftbrk/>@g; $channel_data =~ s@\)@<rtbrk/>@g; $channel_data =~ s@\+@<plus/>@g; $channel_data =~ s@\?@<ques/>@g; $channel_data =~ s@\&apos;@<apos/>@g; $channel_data =~ s@\$@<dollar/>@g; #these escapes are needed for the regex's below to #work properly. while ($channel_data =~ m@<item>(.*?)</item>@s) { $item_info = $1; $mask = $data; #the output mask is set to a copy of the data #handed to the plugin while ($mask =~ m@<d>(.*?)</d>@s) { $get_item = $1; my $item_string; if ($item_info =~ m@<$get_item>(.*?)</$get_item>@s) { $ +item_string = $1; } $mask =~ s@<d>$get_item</d>@$item_string@; } $result .= $mask; $channel_data =~ s@<item>$item_info</item>@@; } } else { $result = "<error>Couldnt find channel tag</error>"; } } else { $result = "<error>Couldnt retrieve url</error>"; }

In reply to Modernisation Needed by simonodell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.