On Wed, 13 Aug 2003 at 14:46:22 +0100, Paul Makepeace wrote:

> This isn't really perl, but it might be mildly fun for a few seconds:
>   $len += $page_size - $len % $page_size if $len % $page_size;
> Any way of doing this in a single arithmetic expression, without the if?

Assuming integers:

$len = $page_size * ( int( ( $page_size + $len - 1 ) / $page_size ) );

If floating point, then the implicit equality comparison doesn't work,
but you can substitute a very small number instead of 1 to make it mostly
work.

Ian

Reply via email to