Concatenate new line

5

How to add a new line separating the inputs into a Perl script?

Example:

I'm using the following script:

#!/usr/bin/perl

print 'oi' . '\n' . 'oi,de novo'

And I call by bash as follows:

perl test.pl > a.txt

When opening the file a.txt I get:

oi\noi, de novo

I would expect the file to be:

oi
oi, de novo
    
asked by anonymous 04.11.2016 / 13:47

1 answer

5

Use double quotation marks " instead of single quotation marks ' , so as to allow interpolation of string , \n will be interpreted as line break rather than literally.

#!/usr/bin/perl

print 'oi' . "\n" . 'oi,de novo'
# print "oi\noi,de novo"

More information: Strings in Perl: quoted, interpolated and escaped

    
04.11.2016 / 14:01