Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] free source blogger

Expand Messages
  • Robin
    Thanks for your comments, about that race condition, I lost your code that you sent me for a better gethead function, can you send it to me again? And yeah, I
    Message 1 of 19 , Apr 30, 2004
    • 0 Attachment
      Thanks for your comments, about that race condition, I lost your code that
      you sent me for a better gethead function, can you send it to me again? And
      yeah, I should probably do something without globals.

      Thanks-Robin

      ----- Original Message -----
      From: "Charles K. Clarkson" <cclarkson@...>
      To: <perl-beginner@yahoogroups.com>
      Sent: Friday, April 30, 2004 6:25 AM
      Subject: RE: [PBML] free source blogger


      > Robin <robin@...> wrote:
      > :
      > : > Robin <robin@...> wrote:
      > :
      > : I don't know, I think my gethead funciton works pretty well
      > : myself, but I suppose a good critique would be in mind.
      > :
      > : here's my latest getfoot function.
      > :
      > : sub getfooter
      > : {
      > : my $footer_sub = shift;
      > : my (@footertoret);
      > : if (-e $footer_sub)
      > : {
      > : open (HEADERF, $footer_sub);
      > : flock (HEADERF, LOCK_SH);
      > : @footertoret = <HEADERF>;
      > : close (HEADERF);
      > : }
      > : else
      > : {
      > : open (HEADERF, ">$footer_sub");
      > : flock (HEADERF, LOCK_EX);
      > : @footertoret = <<END;
      > : </body></html>
      > : END
      > : print HEADERF @footertoret;
      > : close (HEADERF);
      > : }
      > : return (@footertoret);
      > : }
      > :
      > : it's not really much different, but my error checking
      > : routine is going to handle the errors. If you check out
      > : the archives on comp.lang.perl.misc you should see the
      > : post with my latest search engine. The difference is
      > : the way it returns them.
      > :
      > : Overall I agree with what you said, the first part of
      > : what you said is exactly what I've done, race condition
      > : eliminated, at least from my perspective, first check if
      > : the file exists and if it doesn't return the blank list.
      >
      > One race condition is created when more than one process
      > tries to create the footer file simultaneously. Let's face
      > it, most people won't be getting that many hits on a
      > guestbook, but we are here to learn (and teach) what flaws
      > might exist under extreme conditions.
      >
      > And some of us have run into the occasional script that
      > was never written for a high bandwidth server, but is on
      > one none the less.
      >
      > Your new solution, under heavy server load, will create
      > situations where more than one process is trying to create
      > a footer file. That file isn't needed to get the desired
      > result. The desired result of this sub being to return a
      > footer.
      >
      > Creating a file and returning the default footer is also
      > slower than just returning the default footer. And after that
      > default footer is created, returning every subsequent default
      > footer is slower than returning just the default footer.
      >
      > (BTW, perlopentut recommends 'sysopen' for exclusive locks.)
      >
      >
      > : The way you defined your global logic was probably a better
      > : way to do it than mine, but don't you think from the beginner
      > : standpoint it's easier to modify scalars.
      >
      > A beginner programmer -- No. From a non-programmer
      > standpoint it probably doesn't matter. We have to assume they
      > don't understand either.
      >
      >
      > : When someone else modifies my code and they haven't fully
      > : understood hash arrays they might not be able to figure out
      > : how to change some of my code so it functions the way they
      > : would prefer it to be.
      >
      > Presumably, you have added instructions for non-programmers
      > to make changes. Those same instructions are available to the
      > beginner programmer as well. And as a programmer they have
      > access to documentation that explains hashes as well as scalars.
      > Many introductions to Perl include hashes, arrays, and scalars
      > in the same lesson.
      >
      > The best solution would involve the user never touching the
      > program. That's not as hard as it looks. HTML::Template can be
      > used with a template of the script and a form to change
      > configuration variables.
      >
      > My reason for pointing out the globals without offering a
      > solution is that you might find a solution on your own that
      > didn't use globals and fit your writing style. It wouldn't be
      > a foolproof method, but nothing is.
      >
      > Murphy's Eleventh Law:
      >
      > "It is impossible to make anything foolproof,
      > because fools are so ingenious."
      >
      >
      > : However, I will keep working on the project and hopefully
      > : apply some of your comments and suggestions.
      >
      > Thanks for listening. I hope you haven't been discouraged
      > from posting future code and revisions.
      >
      >
      > HTH,
      >
      > Charles K. Clarkson
      > --
      > Mobile Homes Specialist
      > 254 968-8328
      >
      >
      >
      >
      > Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      > Yahoo! Groups Links
      >
      >
      >
      >
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.