Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 15:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found