Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: unpack and endianness Message-ID: <9821@jpl-devvax.JPL.NASA.GOV> Date: 4 Oct 90 22:11:47 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Distribution: comp Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 34 In article thoth@reef.cis.ufl.edu (Gilligan) writes: : : Is there any way to specify the endiannes of the data you are : unpacking? I am writing a perl script to decode Moria save files (for : unspecified purposes :) and unfortunately for me the data is written : in Intel order (LSB first). I can not use unpack (as far as I know) : on the data from our Suns (MSB first). If I could get unpack to : perform the byte shuffling for me it would squish my code by a factor : of two. : Does anyone know how to do this? : : Could it be as simple as : : read(STDIN, $_, 2*2); : ($exp, $maxexp) = unpack("s-2", $_); There's no way to do this with unpack on a big-endian machine at the moment. The best you can do, as far as I can see, is to say sub swab { $_[0] =~ s/([\0-\377])([\0-\377])/$2$1/g; } read(STDIN, $_, 2*2); &swab($_); ($exp, $maxexp) = unpack("s2", $_); : Also, what is the filehandle for <>, I hate having to type : "moriainterp.perl < moria.dc". It's ARGV, but you can't do a read() on it and keep the other semantics of <>. You want something more like open(STDIN,shift). Larry