ravi45722 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to append a file with some text. But some times it starts with new line. Some times the new is not appearing. So, I tried in so many ways. I am tied here.
#!/usr/bin/perl use warnings; use strict; open (FD,">>text.txt"); my $flag = 0; foreach my $num (0 .. 10) { if ($flag == 1) { print FD $/,$num; } if ($flag ==0) { print FD $num; $flag = 1; } }
Expect Output :
Its old text 0 1 2 3 4 5 6 7 8 9 10
Its working some times and not working some times. Why its happening????
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with appending files
by Corion (Patriarch) on Jan 21, 2016 at 13:13 UTC | |
by ravi45722 (Pilgrim) on Jan 21, 2016 at 13:31 UTC | |
by choroba (Cardinal) on Jan 21, 2016 at 14:00 UTC | |
by hdb (Monsignor) on Jan 21, 2016 at 13:47 UTC | |
by ravi45722 (Pilgrim) on Jan 21, 2016 at 14:12 UTC | |
by Corion (Patriarch) on Jan 21, 2016 at 13:33 UTC |