On another point, I forgot to mention: if you're using mixed data in your
output file, you should (that is, -have to-, unless you're brave) *still*
use pack and unpack(), especially if you're reading in mixed data.

For example, if the input file contained the following elements:

<8 ascii characters><32 bit integer><16 bit number><2 ascii characters><16
bit number>

You could use a pack template, such as this:

"a8lsa2s"

(8 ascii characters, followed by a signed long, followed by a signed short,
followed by 2 ascii characters, followed by a signed short)

e.g.:

my $str1 = 'AAbbCcDd';
my $num32 = 60000;
my $num16a = 32765;
my $str2 = 'zX';
my $num16b = 150;

my $binout = pack("a8lsa2s",$str1,$num32,$num16a,$str2,$num16b);
my $cout = pack("C8",$str1);

if(open(WFH,"> temp.out")) {
    binmode(WFH);
    print(WFH "$binout");
    close(WFH);
 }

if(open(RFH,"temp.out")) {
    binmode(RFH);
    while(<RFH>) {
     my @arr = unpack("a8lsa2s",$_);
     foreach my $ent (@arr) {
       print("Entry: $ent\n");
       }
     }
 }

----

prints:

C:\source\aspl>perl pack.pl
Entry: AAbbCcDd
Entry: 60000
Entry: 32765
Entry: zX
Entry: 150

HTH,

!c

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to