working with binary data in Perl...

Alex Beamish talexb-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Fri Sep 29 21:20:45 UTC 2006


On 9/29/06, Lance F. Squire <lance-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org> wrote:
>
> I'm attempting to wright a conversion program for an old byte oriented
> picture description language (NAPLPS/Telidon) to SVG.
>
> I currently have a script in Perl that will give me a human readable
> output from a NAPLPS file. However the code looks like it could have
> been written in BASIC.
>
> eg:
>
> if ( $Byte eq "\e" ) { $Desc = "ESCAPE"; }
> elsif ( $Byte eq chr(15) )
>         {
>         $Desc = "SHIFT-IN - SETTING 'GL' TO 'ASCII (G0)'";
>         $GL = "ASCII";
>         }
> elsif ( $Byte eq chr(14) )
>         {
>         $Desc = "SHIFT-OUT - SETTING 'GL' TO 'PDI (G1)'";
>         $GL = "PDI";
>         }
>
> And doing bit shifts gets really interesting...
>
> #Correcting for missing bytes
> $Pel{X} = chr(ord($Pel{X})<<$Shift);
> $Pel{Y} = chr(ord($Pel{Y})<<$Shift);
>
> My question is: Is there a more elegant way to work with the binary data
> in Perl?


I wonder if it wouldn't be easier to write this in C, since so much of it is
doing binary operations.

You could either write the whole thing in C, or a hybrid Perl/C program to
give you the flexibility of Perl with the speed of C.

I don't have experience with the hybrid, but I have lots of experience with
Perl and with C, and I hear that Inline::C works really well.

Just a thought.

-- 
Alex Beamish
Toronto, Ontario
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/legacy/attachments/20060929/f6aa6483/attachment.html>


More information about the Legacy mailing list