I am stumped.

use strict; use warnings; use v5.10; my @lines = <DATA>; for my $line ( @lines ) { chomp $line; say "\$line is *$line*"; } __DATA__ hello\ngoodbye good\nevil yes\nno

produces

line is *hello\n\ugoodbye* line is *good\nevil* line is *yes\nno*

rather than

line is *hello goodbye* line is *good evil* line is *yes no*

Even though a 2-letter character string looks like one of the "backslashed character escapes" described at p. 68 of Programming Perl (4th ed.) -- here, the newline -- it seems impossible to make those escapes actually "work", if read from a data file. Is there an interpolation rule or exception I'm missing?

Some of the other character escapes listed on that page are \r (carriage return) and \t (horizontal tab).

In the same way, the "translation escapes" described at p. 69, such as \u, don't seem to "work." If hello\n\ugoodbye in the data file (above) is changed to \uhello\n\ugoodbye, the printed result is *\uhello\n\ugoodbye*. I'm looking for

*Hello Goodbye*

I get the same result if I rewrite the program to read from a text file rather than using a __DATA__ block.


In reply to Can't get \n or other character/translation escapes to interpolate if originally read from a data file by davebaker

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.