develooper Front page | perl.perl5.porters | Postings from March 2002

[ID 20020302.001] Data::Dumper creates code which does not workproperly

From:
Eric Joanis
Date:
March 2, 2002 10:18
Subject:
[ID 20020302.001] Data::Dumper creates code which does not workproperly
Message ID:
02Mar2.131418edt.453144-14898@jane.cs.toronto.edu

This is a bug report for perl from joanis@cs.toronto.edu,
generated with the help of perlbug 1.28 running under perl v5.6.0.


-----------------------------------------------------------------
[Please enter your report here]

I have encountered a situation where the output of Data::Dumper cannot be
incorporated in a script to restore the original data, specifically where
a string contains the sequence ^M^J and $Useqq is unset.  Please find
attached a script which illustrates the problem.  (Note:  this arises in
my work because I have packed numbers in a large data structure, and on a
few occasions the packed sequence happens to include ^M^J as a
subsequence.)

The issue arises because perl seems to have a "friendly" way to handle DOS
files on Unix platforms.  My guess is that at a really early stage of
reading the script file, ^M^J is translated to ^J, presumably before perl
is even parsing the input.  Obviously, it is ignoring the single quotes in
this example, since the single quotes should suppress any interpretation
of the input.  (Note that I realize this is generally a desirable
behaviour, so I think the bug is with Data::Dumper, not with how files are
read.)

Note also that, as my script shows, this is not a problem when we use eval
on the output of dump, but only when the code is saved to a file a
compiled back from the file.  (Unfortunately for me, I wish to save the
dump to a file for frequent reuse, so that doesn't help me much...)

An obvious solution is to set $Useqq to 1, but it seems to me this module
ought to output correct code in all cases, so I'm still submitting this as
a bug report.

A somewhat ugly solution is to use something like this:
Replace
    'stuff^M^Jmorestuff'
by
    'stuff' . "\r\n" . 'morestuff'

I don't really like it, but I can't think of any other way to get around
the fact that single quotes don't permit any escape sequences (other than
\\ and \').

Here is the script I wrote to illustrate the problem:
#!/pkgs/perl-5.006/bin/sparc-sun-solaris2.5.1/perl -w

# This short script illustrates a bug with Data::Dumper, where it will
# create code that does not correctly reconstruct the data structure
# dumped when copied into source code.

use Data::Dumper;

$Data::Dumper::Purity = 1;  # This makes no difference

my $a = "\x0d\x0a";
print "Initial length: ", length($a), "\n";

my $dump = Data::Dumper->Dump([$a], [qw(a)]);
print "Dumped code with Useqq = 0:\n", $dump;

eval $dump;
print "New length after eval: ", length($a), "\n";

$Data::Dumper::Useqq = 1;
$dump = Data::Dumper->Dump([$a], [qw(a)]);
print "Dumped code with Useqq = 1:\n", $dump;

eval $dump;
print "New length after eval: ", length($a), "\n";

# This is dump's output when $Useqq = 0. -- Doesn't work!
$a = '
';
print "New length after dumped code (with Useqq = 0): ", length($a), "\n";

# This is dump's output when $Useqq = 1. -- Works correctly
$a = "\r\n";
print "New length after dumped code (with Useqq = 1): ", length($a), "\n";



[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=low
---
This perlbug was built using Perl v5.6.0 - Fri Sep  1 12:37:19 EDT 2000
It is being executed now by  Perl v5.6.0 - Tue Jul  4 17:24:33 EDT 2000.

Site configuration information for perl v5.6.0:

Configured by kol at Tue Jul  4 17:24:33 EDT 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.5.1, archname=sun4-solaris
    uname='sunos gardiner.cs 5.5.1 generic_103640-29 sun4u sparc sunw,ultra-4 '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.7.2
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include '
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt -lsec
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.6.0:
    /h/34/joanis/lib/site_perl/5.005
    /pkgs/perl-5.006/lib/5.6.0/sun4-solaris
    /pkgs/perl-5.006/lib/5.6.0
    /pkgs/perl-5.006/lib/site_perl/5.6.0/sun4-solaris
    /pkgs/perl-5.006/lib/site_perl/5.6.0
    /pkgs/perl-5.006/lib/site_perl
    .

---
Environment for perl v5.6.0:
    HOME=/h/34/joanis
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/h/34/joanis/bin/sun4:/h/34/joanis/bin:/local/bin:/local/X11/bin:/usr/openwin/bin:/usr/ccs/bin:/usr/ucb:/usr/bin:.:/h/34/joanis/bin/hosts:/local/bin/grade:/cs/ai/nlu/wordnet1.7/bin
    PERL5LIB=/h/34/joanis/lib/site_perl/5.005
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About