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:#!/usr/bin/perl use warnings; use strict; my @segtests = (32140578, 32140000, 23400230, 32146578, 32106578, 2130 +1000 ); foreach my $segment_id(@segtests){ my ($shval1,$shval2) = $segment_id =~ /(\d{4})(\d{4})/; print "$shval1 $shval2\n"; #this simulates what happens when the numbers #are passed through the semaphore $shval1 += 0; $shval2 += 0; my $reassemble = connectm($shval1,$shval2); print "$reassemble\n\n"; } sub connectm{ my ($val1,$val2) = @_; # this gives me errors # Left padding a number with 0 (no truncation): # my $padded = sprintf("%0${4}d", $val2); return $val1.$val2; }
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. ??3214 0578 3214578 3214 0000 32140 2340 0230 2340230 3214 6578 32146578 3210 6578 32106578 2130 1000 21301000
But I figure I would ask here, since I'm probably overlooking something, or there is some neat way of doing it. Thanks.
In reply to zero padding by zentara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |