Thursday, March 8, 2012

Create a binary file with some data using Perl

Create a binary file with some data using Perl:


#!/usr/bin/perl
open(FH,"> /tmp/binfile") || die "\nUnable to open file for write mode.\n";
for($i = 0;$i<100;$i++){
$bits = pack( "sai", 200, "TEST", 300000 );
print FH $bits;
}


where
s A signed short (16-bit) value. (200)
a A string with arbitrary binary data, will be null padded. (TEST)
i A signed integer value. (300000)

No comments:

Post a Comment