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 PassedThanks for helping this newbie. Cheers.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; }
In reply to Understanding Regular Expressions by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |