I've been working on some code that will search several html pages in my site and strip out specific lines of html, reformat it the way I want and print to a single page.
right now it sort of works, I can get my lines but it prints the entire line, I am not sure how to write the code to get exactly want I want.
example: current perl code below will find all lines on html pages that have <img src but if a >br< exists on the same line the code prints the entire line like this below.
<img src="http://www.mysite/graphics/blue.jpg" alt="Hey" width="100" height="100" ><br>yada yada
I really just want it to print something like this:
<g:image_link>http://www.mysite/graphics/blue.jpg</g:image_link> on one line.
I am also grabbing hidden forms as well and trying to print the just the values from them as well.
How do strip out
<br> <hr> <b> etc, etc, etc.
I am stuck now and not really sure what to do now thank you for assistance.
#!/usr/bin/perl -T
# Set variables
######################################################################
+#######
$output_file = "../../cgi/generator/source-output.html"; #Chmod 766
######################################################################
+#######
#Pages to Scan
######################################################################
+#######
my @files= qw| ../../page1.html ../../page2.html |;
my @allfiles;
for my $filename(@files){
open FILE, $filename ||
die "Cannot open $filename for reading: $!\n";
push @allfiles, $_ while (<FILE>);
@lines = @allfiles;
$line = @allfiles;
close FILE;
}
#output generator
######################################################################
+#######
open (OUTPUT,">$output_file") || die "Can't Open $output_file: $!\n";
printf OUTPUT "Generator CGI Tester\n\n";
s/\<[^\<]+\>//;
foreach $line (@lines) {
$print_flag = 0;
s/\<[^\<]+\>//;
#generator variables
######################################################################
+#######
###Image
if ($line =~ m/<img src/) {
$img = $line;
printf OUTPUT "$img";
$print_flag = 1;
}
###Form action
if ($line =~ m/<input type=\"hidden\" name=\"description\"/) {
$hidden = $line;
printf OUTPUT "$hidden";
$print_flag = 1;
}
}
close (OUTPUT);
# Redirect browser to generated page
print "Location: $output_file\n\n";
exit;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.