pack V length changes

Discussion in 'Perl Misc' started by Shaun Jackman, Aug 12, 2003.

  1. 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
    Shaun Jackman, Aug 12, 2003
    #1
    1. Advertising

  2. Shaun Jackman

    Bob Walton Guest

    Shaun Jackman wrote:

    > 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


    ....
    > Shaun


    --
    Bob Walton
    Bob Walton, Aug 12, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mitchua
    Replies:
    5
    Views:
    2,715
    Eric J. Roode
    Jul 17, 2003
  2. Tim Jones
    Replies:
    0
    Views:
    369
    Tim Jones
    Jan 31, 2004
  3. Aaron Fude
    Replies:
    2
    Views:
    893
    Daniel Pitts
    Dec 17, 2008
  4. Alexander Farber

    pack 'C3U*' not same as pack 'C3(xC)*'

    Alexander Farber, Jun 23, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    123
    Ilmari Karonen
    Jun 23, 2005
  5. Fabrice

    pack and byte length.

    Fabrice, Sep 18, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    107
Loading...

Share This Page