i love perl but i wish to rant a bit. my script worked perfectly until i changed something somewhere else. the problem seems to be that perl does things behind your back like changing numbers to strings and back again instead of generating an error message. like microsoft windows very nice when it works but very difficult to fix when it does not. this code is a subroutine from a hit counter script which increments the counter in the file when you say Yes but otherwise not. it then goes on to generate a bmp file which contains the graphic of the hit counter. after many days and nights and much pondering i added the line sprintf and all was well. sprintf is what is happening behind your back all the time so why not now? please ignore the flock. it is supposed to make it multi-user. i don't know if it does or not. thank you for reading this.

sub opennumfile{ open(COUNT,$count) or die ("Can't open $count: $!"); flock(COUNT, 1); #shared lock for reading $c = <COUNT> ; close(COUNT) or die ("Can't close $count: $!"); if ($count =~ /\n$/) {chomp($c);} if (!defined($y = param('update'))){ $y = "Yes"; } if (uc($y) eq "YES"){ $c++; open(COUNTER,">$count") or die ("Can't open $count: $!"); flock(COUNTER, 2); #exclusive lock for writing print COUNTER "$c\n$somethingfile\n"; # path to the calling web page close(COUNTER) or die ("Can't close $count: $!"); } $c = sprintf("%d", $c); # essential line but only if $y ne "YES" $nim = $r = length($c); while ($r > 0) { $char[$r] = chop($c); $r--; } }

In reply to sprintf number to string by jobsworth

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.