I would love your advice on this problem. I have a small script that isn't working. What I want it to do is to pull data from .html pages on my website. I want to put a start tag and end tag in the other .html files so I know what data I want copied to my new .html file.
Here is the code.
#!/usr/bin/perl
$start_pattern = '<!-- start section-->';
$end_pattern = '<!-- end section -->';
@files_to_look_in = ("/path/to/files1.html", "/path/to/files2.html");
$write_line = 0;
while(@files_to_look_in)
{
open(HTM_FILE, <$_);
while(<HTM_FILE>)
{
if($_=~/$start_pattern/i)
{
$write_line = 1;
}
if($_=~/$end_pattern/i)
{
$write_line = 0;
}
if($write_line =~ '1')
{
print "$_\n";
}
}
}
Any help would greatly be appreciated. I have tested this, and it doesn't work. I do not get any errors. Nothing shows up.
Thanks
Dean
Update:
Thank you. I got it working. There was a line of code missing for html
print "Content-type: text/html\n\n";
20040329 Edit by castaway: Changed title from 'Perl Monks - what am I doing wrong?'
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.