Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Friday January 09, 2004
01:50 PM

Fileless programs

[ #16741 ]

I am hacking on the iTunes database format, and I needed to do some quick conversions between hexadecimal and decimal representations. I am decent at it by inspection, but the bigger numbers tend to take me more time than a few keystrokes.

These perl one-liners go both ways. Just add an argument. There is probably already some unix command that will do this, too, but I did not spend time looking for it.

perl -e 'printf "%d\n", hex( shift )'
perl -e 'printf "%X\n", shift'

What you do not see is the -l switch, which I like to use a lot, but does not work with printf(), which I never remember.

Since I want these to stick around, I created some bash aliases. I had to goof around with the quotes, but these work.

alias d2h="perl -e 'printf qq|%X\n|, int( shift )'"
alias h2d="perl -e 'printf qq|%d\n|, hex( shift )'"

Now I need to add a one-liner to do a particular date conversion for iTunes, but I am not thinking about the dates at the moment.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.