This is a simple thing, but when you need it - you need it. There is no need in implementing a function that does or looking for a module at CPAN. All you are looking for is already there.
#!/usr/bin/perl -w use strict; # Get the number from the command line or use default. my $number = shift || 42; printf "%b\n", $number;
You might want to refresh you memory of printf or sprintf by flipping though the manual pages.
P.S.: 42 decimal = 101010 binary. Is it cool or what?
3 responses so far ↓
1
Randal L. Schwartz
// Jan 26, 2006 at 6:03 pm
You don’t need the parens after printf, or the 0 between the % and the b.
2
Leonid Mamchenkov
// Jan 26, 2006 at 7:34 pm
Hi Randal, thanks for stopping by. You are right. I updated the post.
3
Malcolm
// Jan 27, 2006 at 1:54 pm
What about the Cypriot reaction to their victorious tennis superstar way down in Melbourne, Australia. I heard Limassol went bananas about their boy Marcos.
Leave a Comment