pack V length changes

S

Shaun Jackman

Running the following little bit
$header = pack "V12 v6 V6 v8", @fields;
print length $header;
prints
100

However, the following
$header = pack "V12 v6 V6 v8", @fields;
print $header;
then (where foo is the above script)
./foo | wc -c
prints
107

Where did the extra 7 characters come from? I'm very confused. Why does the
length of the $header report 100, but 107 characters get printed? Do I have
to set STDOUT to a binary stream somehow?

Please cc me in your reply,
Thanks,
Shaun
 
B

Bob Walton

Shaun said:
Running the following little bit
$header = pack "V12 v6 V6 v8", @fields;
print length $header;
prints
100

However, the following
$header = pack "V12 v6 V6 v8", @fields;
print $header;
then (where foo is the above script)
./foo | wc -c
prints
107

Where did the extra 7 characters come from? I'm very confused. Why does the
length of the $header report 100, but 107 characters get printed? Do I have
to set STDOUT to a binary stream somehow?


Yes.

perldoc -f binmode


....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top