Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

(dkubb) Re: (2) Voting Booth Nodelet Watcher

by dkubb (Deacon)
on Mar 19, 2001 at 05:46 UTC ( #65334=note: print w/ replies, xml ) Need Help??


in reply to Voting Booth Nodelet Watcher

I have just a few comments and questions:

  • At the beginning of the file, you do this:

    my $oldpage = <DATA>;

    And it works every time. When the web pages are downloaded from perlmonks and saved, there are no \n's. When you go to slurp the line of DATA, it returns the web page, because it is only a single line. The only concern I have with this is it relies on vroom not having put \n's on the web page display. If the structure of the web page changes, the code could break.

    Perhaps a slightly better way to do it would be to slurp in every bit of DATA, using something similar to:

    read DATA, my $oldpage, -s DATA;

    This isn't prone to the same problems as the previous line of code.

  • Most of the program is wrapped in curly braces that don't seem to be necessary. Is there a particular reason that it is here, or are they remnants from your original development code?

  • Also, the following snippet will fast forward to just after the __DATA__ tag, and append the new web page information, all using only a single open call:

    open SELF, "+< $0" or die "Can't open $0: $!"; { local $/ = join '', $/, '__DATA__'; <SELF>; #fast forward to the good stuff } truncate SELF, tell SELF; print SELF $/, $newpage; close SELF;

    Just thought you'd like to see this neat trick...

Update: Added in the line to truncate the file to the current position. It is safer than just blindly printing.


Comment on (dkubb) Re: (2) Voting Booth Nodelet Watcher
Select or Download Code
(jcwen) Re: (3) Voting Booth Nodelet Watcher
by jcwren (Prior) on Mar 19, 2001 at 07:17 UTC

    1) Good catch on the <DATA> missing changes if the HTML started containing new lines. Fixed that. While I agree that vroom might change the format, the 'displaytype=raw' is supposed to be packed HTML, with no spaces, newlines, etc. However, it is better defensive programming to add the change, than assume the 'displaytype=raw' will never change.

    2) The curly braces were just localizing the $/ to the file operations. I could have just put them around the read, but I didn't see a problem one way or the other.

    3) Cool trick on the fast-forwarding. I wouldn't have ever thought of that. That's not the kind of tricknology that I'm very good at. I would be concerned that someone picking up script maintainence who is not a sophisticated Perl user would really have to puzzle that out. On the other hand, it suits the purpose so nicely, I put it in.

    I've made the changes and included both versions, with the new version on top, so people can see what changed.

    This is the kind of code that someone who writes in 6 different languages in a single week produces (C, 80386 assembly, 8031 assembly, PHP, Perl, and Forth. I also played with Python for a few minutes). It's not as elegant as it could be, but it is functional.

    --Chris

    e-mail jcwren

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://65334]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-12-25 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls