Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
dear monks,

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. (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...)

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";
Out put is as follows :-
Initial length: 2 Dumped code with Useqq = 0: $a = ' '; New length after eval: 2 Dumped code with Useqq = 1: $a = "\r\n"; New length after eval: 2
what is the problem when $Useqq = 0. It seems, that does not work as expected.

your thoughts on the same.

"Keep pouring your ideas"

2006-10-16 Unapproved by planetscape once evidence of habitual plagiarism uncovered.

In reply to Data::Dumper issue by jesuashok

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 21:27 GMT
Find Nodes?
    Voting Booth?

    No recent polls found