Another way to do this?

From: Trebor A. Rude (treborrude_at_SPAMBGONE.comcast.net)
Date: 04/28/04


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";
}



Relevant Pages

  • Re: Problem passing arguments in WindowsXP
    ... The problem is that perl scripts don't receive argurments if I type ... I read another message suggesting using ftype to see how perl is run ... it displays the current open command string for that file type. ...
    (comp.lang.perl.misc)
  • Re: dbmopen compatibility from perl 5.6 to 5.8
    ... solution but your original post sounded very ungrateful towards the Perl ... > password database files implemented as persistent hashes in perl ... > every line of code that used dbmopen in pre-existing perl scripts, ... open model and refactor the legacy code into an updated open cross ...
    (perl.beginners)
  • No Starch Press releases "Wicked Cool Perl Scripts"
    ... Popular Wicked Cool Book Series Tackles Perl Scripts: ... New book takes Perl programming to the extreme ... Useful Perl Scripts That Solve Difficult Problems" (No Starch Press, ...
    (comp.os.linux.announce)
  • Re: Problem with one perl script executing another, execution started by Apache httpd
    ... support/drivers for accessing RDBMS - something that will change this ... Perl scripts invoking Perl scripts can ... exports a function that does all the real work; ...
    (comp.lang.perl.misc)
  • Re: perl extension for PHP - stuck?
    ... So I want to use my old perl scripts, ... functionality of php. ... One night, being, as I suppose, inspired by love, isidro made a dart at the ...
    (comp.lang.php)