Even i tried this code from the same book . Following is my code
#!/usr/bin/perl use strict; use Fcntl qw (LOCK_EX); use Fcntl; use DB_File; use constant COUNT_FILE => "count.dbm"; my %count; my $num_hits; my $url = $ENV{REQUEST_URI}; local *DBM; print "Content-type : text/plain\n\n"; my $db = tie %count , "DB_File" , COUNT_FILE , O_RDWR | O_CREAT; if( $db ) { my $fd = $db->fd; open DBM , "+<&=$fd" or die "Count not dump DBM for lock: $!"; flock DBM,LOCK_EX; undef $db; $count{$url} = 0 unless exists $count{$url}; $num_hits = ++$count{$url}; untie %count; close DBM; print "$num_hits\n"; }else{ print "[Error processing counter data]\n"; }
Following are my observations

when run the code from my terminal it updates the count and prints

root@inll11325816l:/usr/lib/cgi-bin# perl counter.cgi Content-type : text/plain 11 root@inll11325816l:/usr/lib/cgi-bin# vi counter.cgi root@inll11325816l:/usr/lib/cgi-bin# perl counter.cgi Content-type : text/plain 12 root@inll11325816l:/usr/lib/cgi-bin# vi counter.cgi root@inll11325816l:/usr/lib/cgi-bin# perl counter.cgi Content-type : text/plain 13 root@inll11325816l:/usr/lib/cgi-bin# perl counter.cgi Content-type : text/plain 14

When i run from the Browser it just exits from the if loop and prints the statement in the else block I have another question also here , why there is no check for the URI we are accessing here , wht if the DOCUMENT_URI or REQUEST_URI ( in my case has a different .html file that is been accessed Can anyone please help here ?


In reply to Re^2: simple web counter by Anonymous Monk
in thread simple web counter by fred

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.