Hex to Octal (3 digit) converer

Philip Lord philip at neoncluster.com
Mon May 4 03:12:23 CDT 2015


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
> 
> 



More information about the cctalk mailing list