Dan-LL
asked on
Search File for Dates.
following a question that ozo and adam helped me with, it would like to build on that to make my data clearer to users.
my last question was how to find the html ending tags in a file, remove them, add new data to the file then put the ending tags back.
this is how it stands and works a treat thanks to the experts.
my $tags="</body></html>";
my $datatags="$insertscroll</ body></htm l>";
undef $/; #slurp mode, read files in a whole
open(INFO, "+<$scrpath$scr2") or die "Could not open: $!\n";
my $intext=<INFO>;
$intext=~s/$tags/$datatags /g;
seek(INFO, 0, 0); #Go back to beginning of file
print INFO $intext;
close INFO;
NOW,....
is there a way that I can find a location in the file to put my new data, the idea is that my data is infact dates of meeting/events.
say my html file looked like this
<html><body>
< div id="yyyymmdd">
DATA
</div>
< div id="yyyymmdd">
DATA
</div>
< div id="yyyymmdd">
DATA
</div>
</body></html>
when the code runs it currently collects the date of the meeting into $doe in above format, how can I search through the html file and insert my new data into the right position within the page without losing any data above or below the entry point, top record being the first meeting of the month downwards the last meeting of the month.
Also it is possible that the file may not yet contain any <div> tags if no meeting have been planned or even more than one enrty on a single day so it needs to cope with a file that is just a header and footer or duplicate dates (order not important). I am guessing this will need a lot of condtions so have set the points high to reflect your efforts.
my last question was how to find the html ending tags in a file, remove them, add new data to the file then put the ending tags back.
this is how it stands and works a treat thanks to the experts.
my $tags="</body></html>";
my $datatags="$insertscroll</
undef $/; #slurp mode, read files in a whole
open(INFO, "+<$scrpath$scr2") or die "Could not open: $!\n";
my $intext=<INFO>;
$intext=~s/$tags/$datatags
seek(INFO, 0, 0); #Go back to beginning of file
print INFO $intext;
close INFO;
NOW,....
is there a way that I can find a location in the file to put my new data, the idea is that my data is infact dates of meeting/events.
say my html file looked like this
<html><body>
< div id="yyyymmdd">
DATA
</div>
< div id="yyyymmdd">
DATA
</div>
< div id="yyyymmdd">
DATA
</div>
</body></html>
when the code runs it currently collects the date of the meeting into $doe in above format, how can I search through the html file and insert my new data into the right position within the page without losing any data above or below the entry point, top record being the first meeting of the month downwards the last meeting of the month.
Also it is possible that the file may not yet contain any <div> tags if no meeting have been planned or even more than one enrty on a single day so it needs to cope with a file that is just a header and footer or duplicate dates (order not important). I am guessing this will need a lot of condtions so have set the points high to reflect your efforts.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I agree with FishMonger. Instead of updating the HTML file everytime you get new data, you should set it up like this:
1) Have a template file (either HTML::Template or Template::Toolkit) that contains the HTML framework, and placeholders for what you want. This file doesn't change - it is always the same.
2) Have a file that contains the details to fill in the template (eg: date and data). This file is updated whenever you get new data to add.
3) Have the final HTML file. This is generated from file #2 whenever file #2 is updated
Your perl script, instead of updating the HTML file directly, will update file #2. Then, using the template (#1) and that file that contains the data (#2), it'll generate the html (#3).
1) Have a template file (either HTML::Template or Template::Toolkit) that contains the HTML framework, and placeholders for what you want. This file doesn't change - it is always the same.
2) Have a file that contains the details to fill in the template (eg: date and data). This file is updated whenever you get new data to add.
3) Have the final HTML file. This is generated from file #2 whenever file #2 is updated
Your perl script, instead of updating the HTML file directly, will update file #2. Then, using the template (#1) and that file that contains the data (#2), it'll generate the html (#3).
ASKER
looking at the fact i could have duplicate dates I have changed the div tag id's to save getting grief from W3C.
file now looks like
<html><body>
<!---yyyymmdd--->
<div>
DATA
</div>
<!---end of yyyymmdd--->
<!---yyyymmdd--->
<div>
DATA
</div>
<!---end of yyyymmdd--->
</body></html>
file now looks like
<html><body>
<!---yyyymmdd--->
<div>
DATA
</div>
<!---end of yyyymmdd--->
<!---yyyymmdd--->
<div>
DATA
</div>
<!---end of yyyymmdd--->
</body></html>
ASKER
ok, i'm going away to have a play, as windows update says "this could take a few minutes" (hours),
thanks for getting me lost, erm started i mine, I will return with how I got on/off
thanks for getting me lost, erm started i mine, I will return with how I got on/off
ASKER