Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

(zdog) Re: One-Line Web Counter

by zdog (Priest)
on Sep 09, 2001 at 07:02 UTC ( #111240=note: print w/ replies, xml ) Need Help??


in reply to One-Line Web Counter

Golfing!! I'm pretty sure this would also work:

perl -MCGI -e 'print CGI->new->header;open(F,"c");($c)=<F>;print ++$c; +close F;open(N,">c");print N $c;'

Zenon Zabinski | zdog | zdog7@hotmail.com


Comment on (zdog) Re: One-Line Web Counter
Download Code
Replies are listed 'Best First'.
(jj808) Re: (zdog) Re: One-Line Web Counter
by jj808 (Hermit) on Sep 09, 2001 at 16:36 UTC
    More golf...

    Do echo "0" >c first.

    perl -MCGI -i -e 'while(<>){s!(\d+)!$t=$1+1!e;print}print CGI->new->h +eader,$t' c

    JJ

    Update: Removed useless semicolon.

    Update 2: Even smaller now!

      Well leaving aside locking issues, and the point that the number 2 by itself is not exactly valid html, here is the above made even shorter.
      perl -MCGI -pi -e 'END{print&CGI::header,$t}s/\d+/$t=$&+1/e' c
      UPDATE
      And, of course, there is always a shorter way:
      perl -MCGI -pi -e'END{print&CGI::header,$t}$t=++$_' c

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2015-07-31 01:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls