Hi,

I am a newbie on perl and trying to understand regular expression usage, how it works and also trying to accomplish a task of converting an html page into an RSS feed. I came accross a script which does conversion for known sites and one could modify the script to add more sites. All one needs to do is add the details of formatting to capture.

A portion of the code written in the program is detailed below

Parameters Passed
$url = http://www.sfgate.com/examiner/bondage/
$html = Is the content of the URL specified

Can someone help me document each section of the following code. And If had to do something like this for the URL http://bsewebx.bseindia.com/qresann/announce.asp what would the code look like and what would be the changes.

sub do_bondagefiles { my ($url, $html) = @_; $_ = $html; 1 while (s@<!--.*?-->@ @gsi); # lose comments s/[\r\n]+/ /gs; s@^.*?(<A HREF=\"[^\"]*article\.cgi)\b@$1@is || error ("unable to trim head in $url"); s@<[^<>]*\bblacktri\.gif\b.*$@@is || error ("unable to trim tail in $url"); s@(<A\b[^<>]*\bHREF\b)@\n\001\001\001\n$1@gi; my @sec1 = split (/\n\001\001\001\n/s); my @sec2 = (); foreach (@sec1) { next if (m/^\s*$/s); s@^\s*<A\b[^<>]*?\bHREF=\"([^<>\"]+)\"[^<>]*>\s*(.*?)\s*</A>\s*@@i +s || error ("unparsable entry (url) in $url"); my $eurl = $1; my $title = $2; my $date = ''; my $body = $_; $body =~ s@<[^<>]*>@@g; # lose tags in body push @sec2, ($eurl, $date, $title, $body); } return @sec2; }
Thanks for helping this newbie. Cheers.

In reply to Understanding Regular Expressions by Anonymous Monk

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.