We help IT Professionals succeed at work.

Search File for Dates.

Dan-LL
Dan-LL asked
on
Medium Priority
153 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.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
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.
Top Expert 2009

Commented:
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).

Author

Commented:
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>

Author

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.