Hello all,

I'm having a problem with (I suppose) pattern matching.
Here's the task: To take binary data from windows(little-endian)
and convert to Unix(big-endian).  If the file is all numeric, I don't
have a problem, but it isn't.  I need to be able to recognize that
one of the four bytes is non-numeric data (spaces, alpha, punctuation..).
If one of the four is non-numeric then I don't want to do the byte
swapping.  Right now if there is character data it gets swapped so 'TEST'
becomes 'TSET'.  I've been searching the web, but haven't found anything
that works for me.

any help would be greatly appreciated...
thank you,
andy

Here's the source...(Let me know if any additional info is needed)

#!/usr/bin/perl
  $BINARYFILE = "DATA";
#
  ($device,$irn,$fileInfo,$links,$userID,$groupID,$deviceID,$size,
   $access,$modify,$inrChange,$preferredIO,$IO) = stat($BINARYFILE);
  open(INFILE,$BINARYFILE) or die("Error: file not opened for read!\n");
  binmode(INFILE);
#
# Need to get the file size
#
  read(INFILE,$indata,$size);
  close(INFILE);

  $newdata = '';

  $indata =~ s/\004/\004\0\0\0/g;
  for ($i=0; $i < $size ; $i++){
    $bytes = substr $indata, $i*4, 4;
# *** THIS IS THE PROBLEM AREA -- I THINK.
    if ($bytes =~ /^(\D{4})/ )
    {
     $newdata .= $bytes;
    }else
     {
     $newdata .= reverse $bytes;
     }
  }

# $xl_double = pack("d", $num);
# my @bytes = split(//, $xl_double);
# @bytes = reverse(@bytes);
# $xl_double = join('', @bytes);

# dump the new data, here set to overwrite
  $newfile = $BINARYFILE;
  print "$BINARYFILE --> $newfile\n";
  open NEW, ">$newfile" or die "Failed to open new file: $newfile\n";
  print NEW $newdata;
  close(NEW);



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to