I have never had consistent success with unpack.  It seems like it works
once, but never again.  here is a pretty stripped down example of reading
from a simple binary file with a simple unpacking.  PLEASE let me know what
my stupid error is, because I have been hammering my Perl CD bookshelf and
can't figure it out.

-----------------------------------------
test.pl:
-----------------------------------------
#!/usr/bin/perl -w

use strict;
use Carp;
use Data::Dumper; 

my $source_path = shift;

open SOURCE, "<:raw", $source_path or die "screaming:$!";

my $buffer = "";
my $index = 0;
while (read SOURCE, $buffer, 1, $index)
{
    my @chars = unpack "C", $buffer;
    print Dumper([EMAIL PROTECTED]);
    print Dumper(\$buffer);
    $index++;
    $buffer = "";
}

-----------------------------------------
hexdump of test.bic:
-----------------------------------------
00000000  42 49 43 20 56 33 2e 32  |BIC V3.2|
00000008  38 00 00 00 4a 04 00 00  |8...J...|
00000010

-----------------------------------------
result of ./test.pl test.bic:
-----------------------------------------
$VAR1 = [
          66
        ];
$VAR1 = \'B';
$VAR1 = [
          0
        ];
$VAR1 = \'I';
$VAR1 = [
          0
        ];
$VAR1 = \'C';
$VAR1 = [
          0
        ];
$VAR1 = \' ';
$VAR1 = [
          0
        ];
$VAR1 = \'V';
$VAR1 = [
          0
        ];
$VAR1 = \'3';
$VAR1 = [
          0
        ];
$VAR1 = \'.';
$VAR1 = [
          0
        ];
$VAR1 = \'2';
$VAR1 = [
          0
        ];
$VAR1 = \'8';
$VAR1 = [
          0
        ];
$VAR1 = \'';
$VAR1 = [
          0
        ];
$VAR1 = \'';
$VAR1 = [
          0
        ];
$VAR1 = \'';
$VAR1 = [
          0
        ];
$VAR1 = \'J';
$VAR1 = [
          0
        ];
$VAR1 = \'';
$VAR1 = [
          0
        ];
$VAR1 = \'';
$VAR1 = [
          0
        ];
$VAR1 = \'';

-----------------------------------------
Thane
Thane at crashbox dot com 

Reply via email to