[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-08-07
6
Medium Priority
?
216 Views
Last Modified: 2010-03-05
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.
0
Comment
Question by:lenz8as
6 Comments
 
LVL 17

Expert Comment

by:jasonsbytes
ID: 19646826
This will print 4 new lines:
print FH "\n\n\n\n";
0
 
LVL 17

Accepted Solution

by:
jasonsbytes earned 750 total points
ID: 19646845
[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
 
LVL 39

Expert Comment

by:Adam314
ID: 19647146
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lenz8as
ID: 19647611
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
 
LVL 17

Expert Comment

by:jasonsbytes
ID: 19647785
You should be using print, not printf
0
 
LVL 85

Expert Comment

by:ozo
ID: 19648107
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question