Z
Zoran
Hello,
I have problems with unpacking binary data(win98,activestate perl).
The procedure is very simple:
1.Packing ascii data as binary data.
2.Unpacking binary data.
3.Printing the output.
This is my input file:
0.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
0.2 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.3 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.2 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
This is the output:
0.1 0 0 0 0 0 0 0 0 0 0 0 0 0
0.2 0 0 0 0 0 0 0 0 0 0 0 0 0
1.1 0 0 0 0 0 0 0 0 0 0 0 0 0
1.5 0 0 0 0 0 0 0 0 0 0 0 0 0
2.1 0 0 0 0 0 0 0 0 0 0 0 0 0
2.3 0 0 0 0 0 0 0 0 0 0 0 0 0
2.5 0 0 0 0 0 0 0 0 0 0 0 0 0
3.1 0 0 0 0 0 0 0 0 0 0 0 0 0
3.2 0 0 0 0 0 0 0 0 0 0 0 0 0
3.5 0 0 0 0 0 0 0 0 0 0 0 0 0
As you can see only the first numbers are correct.Maybe I am making
mistakes ,when I try to pack the data in a special format
@var= pack ("d I d11",$buf); .
This is the code:
______________________________________________________
print "\n ******************************\n";
open (B ,"< stats.dat") or die "failed opening stats.dat \n";
open (C ,"> bin.dat") or die "failed creating bin.dat \n";
while (my $buf = <B>)
{
chomp $buf;
@var2 = pack("d I d11",$buf);
print C "@var2\n";
}
close(C);
close(B);
open (B ,"< bin.dat") or die "failed opening bin.dat \n";
open (C ,"> asc.dat") or die "failed opening asc.dat \n";
binmode(B);
while ($buf2=<B>)
#while (read B,$buf2,102)
{
chomp $buf2;
@var = unpack("d I d11",$buf2);
print C "@var\n";
print " @var\n";
}
close(C);
close(B);
print " Operation done\n";
print " ******************************\n";
__________________________________________________
I have problems with unpacking binary data(win98,activestate perl).
The procedure is very simple:
1.Packing ascii data as binary data.
2.Unpacking binary data.
3.Printing the output.
This is my input file:
0.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
0.2 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.3 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.2 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
This is the output:
0.1 0 0 0 0 0 0 0 0 0 0 0 0 0
0.2 0 0 0 0 0 0 0 0 0 0 0 0 0
1.1 0 0 0 0 0 0 0 0 0 0 0 0 0
1.5 0 0 0 0 0 0 0 0 0 0 0 0 0
2.1 0 0 0 0 0 0 0 0 0 0 0 0 0
2.3 0 0 0 0 0 0 0 0 0 0 0 0 0
2.5 0 0 0 0 0 0 0 0 0 0 0 0 0
3.1 0 0 0 0 0 0 0 0 0 0 0 0 0
3.2 0 0 0 0 0 0 0 0 0 0 0 0 0
3.5 0 0 0 0 0 0 0 0 0 0 0 0 0
As you can see only the first numbers are correct.Maybe I am making
mistakes ,when I try to pack the data in a special format
@var= pack ("d I d11",$buf); .
This is the code:
______________________________________________________
print "\n ******************************\n";
open (B ,"< stats.dat") or die "failed opening stats.dat \n";
open (C ,"> bin.dat") or die "failed creating bin.dat \n";
while (my $buf = <B>)
{
chomp $buf;
@var2 = pack("d I d11",$buf);
print C "@var2\n";
}
close(C);
close(B);
open (B ,"< bin.dat") or die "failed opening bin.dat \n";
open (C ,"> asc.dat") or die "failed opening asc.dat \n";
binmode(B);
while ($buf2=<B>)
#while (read B,$buf2,102)
{
chomp $buf2;
@var = unpack("d I d11",$buf2);
print C "@var\n";
print " @var\n";
}
close(C);
close(B);
print " Operation done\n";
print " ******************************\n";
__________________________________________________