Hex to Octal (3 digit) converer

Ian S. King isking at uw.edu
Mon May 4 21:07:41 CDT 2015


But now he has Perl on his computer.  Eww.

On Mon, May 4, 2015 at 1:12 AM, Philip Lord <philip at neoncluster.com> wrote:

> Perfect…seems to work great!
>
> Thanks!!!
>
> > On May 4, 2015, at 7:54 PM, Don North <north at alum.mit.edu> wrote:
> >
> > On 5/4/2015 12:23 AM, Philip Lord wrote:
> >> Thanks again, I’ve never used Perl either, but I just installed it.
> >>
> >> So I saved your script as a textfile called HEX_OCTAL.pl:
> >>
> >> perl -n -e 'print join(" ",map(sprintf("%03o",hex($_)),split("
> ")))."\n";'
> >>
> >> But unfortunately I get the following error when I try to run it:
> >>
> >> syntax error at /Users/Philip/perl5/perlbrew/Perl_tests/HEX_OCTAL.pl
> line 1, near "n -e "
> >> Execution of /Users/Philip/perl5/perlbrew/Perl_tests/HEX_OCTAL.pl
> aborted due to compilation errors.
> >>
> >> Not sure what I’m doing wrong…being a noob, it could be anything!
> >>
> >> Phil
> >>
> >
> > There are two ways to resolve this.
> >
> > First, you just put the command line I gave you into a shell script file
> (call it conv.sh):
> >
> >    #!/bin/bash
> >    perl -n -e 'print join(" ",map(sprintf("%03o",hex($_)),split("
> ")))."\n";'
> >
> > Then just type './conv.sh' on the command line to run in interactive
> mode, or './conv.sh < test.dat' to source data from a file test.dat.
> >
> > Or, second, to turn the perl one-liner into a real perl program, it
> needs to be this (call it conv.pl):
> >
> >    #!/usr/bin/perl
> >    while (<>) { print join(" ",map(sprintf("%03o",hex($_)),split("
> ")))."\n"; }
> >    exit;
> >
> > then you can run this in the same way as above, except type './conv.pl'
> or './conv.pl < test.dat'
> >
> > Don
> >
> >
>
>


-- 
Ian S. King, MSIS, MSCS, Ph.D. Candidate
The Information School <http://ischool.uw.edu>

Archivist, Voices From the Rwanda Tribunal <http://tribunalvoices.org>
Value Sensitive Design Research Lab <http://vsdesign.org>

University of Washington

There is an old Vulcan saying: "Only Nixon could go to China."


More information about the cctalk mailing list