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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |