Just another Perl shrine | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
First I've read "perldoc -q zero" and I don't seem to get it, or this problem is a bit trickier. What I'm trying to do is use SysV semaphores to pass 8 digit integers. This is part of a scheme I'm working on to let unrelated apps get a shared memory segment automatically, by just possesing a key. It all works well, except for 1 glitch. It seems that (on my linux anyways) each semaphore array element is limited to 4 digits. ( I nearly tore my last few hairs out trying to discover why 8 digit semaphores always came back as 0 ).
Anyways, I made a work around to split the 8 digit numbers into 2 4 digit sets, then place them into 2 semaphores. Now the clients just need to read the 2 semaphores, and combine them back to the original. Now a problem occurs because perl will convert 0000 to 0, or 0230 to 230, or 0002 to 2. So here is a little script which demonstrates the problem. OUTPUT:
The problem comes with the first 3 tests. The middle example is easy enough, test for 0, and multiply by 10000 to get the result. The second test "2340 0230" is the difficult one. If it comes through as 230, how to I left pad a 0 to make it a numeric 0230. I figure everything has to be converted to strings, concated, then converted back to number by adding 0. ?? But I figure I would ask here, since I'm probably overlooking something, or there is some neat way of doing it. Thanks. I'm not really a human, but I play one on earth. flash japh In reply to zero padding by zentara
|
|