Another way to do this?
From: Trebor A. Rude (treborrude_at_SPAMBGONE.comcast.net)
Date: 04/28/04
- Next message: John Bokma: "Perl Projects?"
- Previous message: pembed2003: "Re: Regex to format 1234 to 1,234"
- Next in thread: Tassilo v. Parseval: "Re: Another way to do this?"
- Reply: Tassilo v. Parseval: "Re: Another way to do this?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 28 Apr 2004 05:02:48 GMT
In an effort learn Perl, I was converting some of my smaller C++ programs to
Perl scripts. I had one program which printed out the bytes of an integer
as characters (so 0x616263 would be "abc"). I've got a Perl solution, but
for some reason it seems unnecessarily complicated. Is there a better way
to accomplish the same thing as the script below? I keep thinking that pack
or unpack can do it, but darned if I can figure out how.
#!/usr/bin/perl -w
use strict;
for (@ARGV)
{
$_ = oct if /^0/;
my @bytes;
do { unshift @bytes, $_ & 0xFF; } while (($_ >>= 8) > 0);
print chr for @bytes;
print "\n";
}
- Next message: John Bokma: "Perl Projects?"
- Previous message: pembed2003: "Re: Regex to format 1234 to 1,234"
- Next in thread: Tassilo v. Parseval: "Re: Another way to do this?"
- Reply: Tassilo v. Parseval: "Re: Another way to do this?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|