in reply to String eval is cool

$mask = eval '0b' . ( 1 x $bits ) . ( 0 x ( 32 - $bits ) );
Or you could have used the function that perl provides for this purpose:
$mask = oct '0b' . ( 1 x $bits ) . ( 0 x ( 32 - $bits ) );

Replies are listed 'Best First'.
Re^2: String eval is cool
by ikegami (Patriarch) on Jun 23, 2006 at 14:41 UTC
    Wow, what a misnomer! I didn't know oct did that. I've been using my own pack-unpack-based routine to convert from binary.