?
Solved

Search File for Dates.

Posted on 2009-02-17
5
Medium Priority
?
136 Views
Last Modified: 2012-05-06
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></html>";

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.
0
Comment
Question by:Dan-LL
  • 3
5 Comments
 
LVL 28

Accepted Solution

by:
FishMonger earned 2000 total points
ID: 23662711
Based on my limited knowledge of what you're doing, I'd say the best option would be to use a template.

Take a look at HTML::Template
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm
0
 
LVL 1

Author Comment

by:Dan-LL
ID: 23662927
hmm, i get the idea but feel I may be out of my depth here and wondering if templates would involve re-writing too much code to be worth it, like the idea though, me a html, css, javascript junkie, perl=new to me still.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 23662937
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).
0
 
LVL 1

Author Comment

by:Dan-LL
ID: 23663013
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>
0
 
LVL 1

Author Comment

by:Dan-LL
ID: 23663071
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question