in reply to Re^3: Help with pack error
in thread Help with pack error
I wonder if UTF-8 is automatically selected as I don't turn it on at all. Here's the full code.
#!/usr/bin/perl -w use strict; use LWP; use Getopt::Long; ## ## GLobal variables ## my $primary_server = ""; my $timeout = 30; # No. of seconds to wait for request to timeout my $uagent; # User Agent object my $line; # A Line read from the order file my $mtid; # First 4 digits of the input line my $bits; # Bit flags (64 or 128, first bit of 1 = 128) my $bitsize; # The length of bit flags (either 64 or 128) my $byte; # eight bit flags. my $data; # The data my $reqsize; # The length of the fully packed request. my $request; # Holds the full request line converted to binary my $cmd_line; # Holds the xml command to submit my $reply; # Holds raw reply from server my $error_flag; # Err flag (0=no error, 1=timeout, 2=failed) my $i; # counter my $dummy; ############################################################ ## MAIN main MAIN main MAIN main MAIN main MAIN main MAIN ## ############################################################ # # Read. # #$primary_server = <STDIN>; #$primary_server =~ s/\n//; # # Read the input line from STDIN. # $line = <STDIN>; $line =~ s/\n//; $mtid = substr( $line, 0, 4 ); $reqsize = 4; $bits = substr( $line, 4, 1 ); if ($bits eq "1") { $bitsize = 128; $reqsize += 16; } else { $bitsize = 64; $reqsize += 8; } $bits = substr( $line, 4, $bitsize ); $data = substr( $line, 4 + $bitsize ); $reqsize += length( $data ); $request = pack( "n", $reqsize ); $request .= $mtid; $request .= pack( 'B*', $bits ); $request .= $data; print STDOUT $request;
Note that this is still a work in progress and several pieces - including the communications and response - have not been coded, yet. I'm just trying to see if I can get this to work for building binary data.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Help with pack error
by BrowserUk (Patriarch) on Mar 21, 2012 at 16:27 UTC |