#!/usr/bin/perl -w
# small script to convert the packed neighbor binary data to text data

use strict;

# open up the filename specified by the first parameter and read in the data
my $filename = shift;
open my $fh, '<', $filename or die $!;
binmode $fh;
my @data = <$fh>;
close $fh;

chomp @data;

# discard length/width data
shift @data;
shift @data;

my @output;
for my $line (@data) {
	my @line_out;

	# operate on each binary packed character
	for my $char (split //, $line) {
		my $binstr = unpack('B*', $char);

		# grab bits 7, 5, 3, and 1.
		push @line_out, join '', $binstr =~ /(\d)\d (\d)\d (\d)\d (\d)\d/x;
	}

	# separate each tile in this line by spaces
	push @output, join ' ', @line_out;
}

# separate each row with a newline
print join "\n", @output;
