Skip to content

Heredocs silently change literal \r\n's and \r's to \n #17770

@haukex

Description

@haukex
use warnings;
use strict;
use Data::Dumper;
$Data::Dumper::Useqq=1;

print Dumper( eval           qq{"X\r\nY \r\n A \r B\n"}   or die $@ );
print Dumper( eval qq{<<"EOF"\r\nX\r\nY \r\n A \r B\nEOF} or die $@ );

Output:

$VAR1 = "X\r\nY \r\n A \r B\n";
$VAR1 = "X\nY \n A \n B\n";

I would have expected both outputs to be the same, that is, "X\r\nY \r\n A \r B\n". I've looked in the docs (perlop in particular), the Camel, and the issue tracker, but haven't found anything that documents this behavior.

Although it's possible I may have missed it in the docs, there are statements in the documentation that I find misleading, such as in the description of <<EOF in perlop: "Double quotes [on the terminator] indicate that the text will be interpolated using exactly the same rules as normal double quoted strings."

I think that the docs should be clarified to describe this behavior in a prominent place, and if someone could confirm that this behavior is intentional and not a bug, I could provide a doc patch. Otherwise, if this behavior isn't intentional, that would make this a real bug.

This behavior seems to be the same across all Perl releases since 5.6.2 (and probably before, I just don't have one installed to test on).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions