#497 bug about pack, unpack

open
nobody
None
5
2008-05-03
2008-05-03
Anonymous
No

If two data is combined with one with a "pack" function and it divides into two data with a "unpack" function, the divided data will not be normally displayed by Eclipse Console.
When perl is started in a terminal, the divided data is displayed normally.
This probram can be checked by the following programs.

#----------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my $data = 2008;
my $str = "abcde";
my $buf_data;
my $buf_str;
my $rec;

print "$str : $data\n";

$rec = pack "a12 l", $str ,$data;
($buf_str, $buf_data) = unpack "a12 l", $rec;

print "$buf_str\n"; # good
print "$buf_data\n"; # good
print "$buf_str : $buf_data\n"; # bad
#----------------------------------------

Discussion

  • Jan Ploski
    Jan Ploski
    2008-05-14

    Logged In: YES
    user_id=86907
    Originator: NO

    The difference is caused by outputting of a null character. The following simpler example also demonstrates this strange behavior:

    print "abc".chr(0)."def\n"; # only "abc" printed in Eclipse