PERL: How to print few new lines in sequence into a file?

PERL: How to print few new lines in sequence into a file?
Eg: printf FH "\n\n\n\n";
It will not print 4 newlines for me.
lenz8asAsked:
Who is Participating?
 
jasonsbytesCommented:
[root@ip-208-109-106-75 ~]# cat test.p
#!/usr/bin/perl

open (FH, ">temp");
print FH "hi\n";
print FH "\n\n\n\n";
print FH "bye\n";
close (FH);

[root@ip-208-109-106-75 ~]# ./test.p
[root@ip-208-109-106-75 ~]# cat temp
hi




bye
0
 
jasonsbytesCommented:
This will print 4 new lines:
print FH "\n\n\n\n";
0
 
Adam314Commented:
printf is used to do formatting before printing.  See here for details:
http://perldoc.perl.org/functions/printf.html

Unless you need the formatting provided by printf, you should generally use print.

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
lenz8asAuthor Commented:
jasonsbyte,

I copy exactly your code, but what i got is only signel new line in my temp file.
Theorytically i believe your script should works and i should see 5 empty line between "hi" and "bye".

So, is that anything else that may affect the behavior/functionality of this printf basic command?
0
 
jasonsbytesCommented:
You should be using print, not printf
0
 
ozoCommented:
Since there are no format conversion characters in those strings, the result of a printf should be identical to the result of a print (unless you have $\ set)
But I agree that print is more efficient and preferable to use when you aren't doing any format conversions.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.