Hi
I am appending the data to a file . I want this to happen from a newline everytime the script is run.For eg.
the file1.txt contains
A quickcfsgggdra ertge
Brown fox s;ofj;ekf;okfo
jumped sldkfhlrigje
Now I want to append the follwoing data from file2.txt
over the lazy dog
now file1.txt should look like
A quickcfsgggdra ertge
Brown fox s;ofj;ekf;okfo
jumped sldkfhlrigje
over the lazy dog
Please suggest the code!
14 3058 http://perldoc.perl.org/functions/open.html
Simply open the file handle in append mode, and be sure that each line that you print ends in a new line character. -
open(OUT, ">> file1.txt") or die "open $file1.txt failed: $!";
-
print OUT "Your next line of data\n";
-
close OUT;
-
Also, browse the faq on files provided by perldoc at some point. And at the very least keep it bookmarked if you want to quick answers to a lot of the comment file questions: http://perldoc.perl.org/perlfaq5.html
@homesick123
The 3-arg form of open() should be preferred: - open(OUT, ">>", "file1.txt") or die "open $file1.txt failed: $!";
instead of - open(OUT, ">> file1.txt") or die "open $file1.txt failed: $!";
Greetz, Doc
The 3-arg form of open() should be preferred:
Why is that preferred?
Not even the examples on the perdoc site use the 3 argument form: - open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
-
or die "Can't open mailbox: $!";
-
Why is that preferred?
Not even the examples on the perdoc site use the 3 argument form: - open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
-
or die "Can't open mailbox: $!";
-
Dear Kevin!
Study this "http://perldoc.perl.org/functions/open.html" carefully and you will know it.
Greetz, Doc
To docsnyder,
It is not preferred. It is simply preferred by "you".
If you want to debate your reasoning, feel free. But I can assure you that Kevin has read the docs before many times, as have I.
To docsnyder,
It is not preferred. It is simply preferred by "you".
If you want to debate your reasoning, feel free. But I can assure you that Kevin has read the docs before many times, as have I.
Dear miller!
If you have read my posting carefully, you should have noticed, that my way of "direct" help has been a benefit to a lot of peoples anywhere in the world (do you really request a list of positive answers right now? Believe me, there is one.). But in my eyes, the help that is given in "thescripts" is in a "VERY" poor shape! In my preferred forum (http://board.perl-community.de (sorry, but it's german)), people help each other in a way, I never have encountered anywhere else. Even if total novice asks a question, and he/she will get an answer. In "thescripts" I noticed the fact, that seldomly anyone is trying to answere a question, but stating one more question is more frequently the case.
Miller et all: If you really have read the reference (let's assume Kevin have done it!) I pointed out (see my last mail): I can hardly understand, why you oppose to my aim/conviction!
Greetz, Doc
Dear Doc!
As I suspected (well, already knew) there is no mention of the three argument syntax being prefered. It is simply a different way of doing something that can be handy in certain situations.
Dear Doc!
As I suspected (well, already knew) there is no mention of the three argument syntax being prefered. It is simply a different way of doing something that can be handy in certain situations.
O.K. Kevin, use the 2-argument syntax if you feel lucky with it. If the arguments of the cited article did not convince you, I can life with it. I prefere to life another style of (programming-)life.
Greetz, Doc
There you go, it's your preference, not "the" prefered way to open files with perl. The documentation in the link you posted (and in the opentut) makes that very clear. Thats all for me on this subject.
@Kevin
There you go, it's your preference, not "the" prefered way to open files with perl. The documentation in the link you posted (and in the opentut) makes that very clear. Thats all for me on this subject.
Have you ever thought about security issues? With the "2 arg" form of open(), which typically appears like
it may happen, that $file gets a value which is far away from what you intended to to. Think for example, $file is set to ARGV[0]. A horror vision!!! Someone could execute arbitrary code! Did you take this into account?
The described risk of exploitation is not given with the "3 arg" form of open().
Greetz, Doc
P.S. If it turns out that to be secure is only "my own personal preferrence", O.K., I can live with it.
@Kevin
Have you ever thought about security issues? With the "2 arg" form of open(), which typically appears like
it may happen, that $file gets a value which is far away from what you intended to to. Think for example, $file is set to ARGV[0]. A horror vision!!! Someone could execute arbitrary code! Did you take this into account?
The described risk of exploitation is not given with the "3 arg" form of open().
Greetz, Doc
P.S. If it turns out that to be secure is only "my own personal preferrence", O.K., I can live with it.
No, in ten+ years of coding perl I have never thought about security issues.
Have you never heard of validating or untainting data before it's used as a filehandle or for any other insecure purpose?
Does being a condescendng **** come natural to you or does it take effort? ;)
Ok guys,
You have got to stop arguing like this in threads. The OP doesn't need to be entertained in this manner. Kevin, use of profane language of any type is strictly prohibited on this site and repeated use can lead to a temporary site ban so please be more careful.
You both have the right to express different opinions and it's up to the OP which opinion they take but please do so without attacking each other. If you have a difference of opinion and want to argue a point then please do so using the PM system and in a polite and respectful manner.
The issue here is not who is right in this argument but the fact that you are essentially hijacking the original posters thread for your own argument. If I were the original poster I would be afraid to reply with any questions for fear of being drawn into the argument. This has got to stop.
If you wish to comment any further on this matter with me please contact me by PM.
Mary
No, in ten+ years of coding perl I have never thought about security issues.
Have you never heard of validating or untainting data before it's used as a filehandle or for any other insecure purpose?
Does being a condescendng **** come natural to you or does it take effort? ;)
Tainted data is only complained by Perl when executing binaries with the set-uid-bit enabled for binaries owned by root. Since a lot of sensible files are at least readable anyhow, someone could exploit sensible data this way, even beeing an ordinary user, with no "tainted data mechanism" in affect.
If you never ran into trouble about this issue since ten years, be happy that you obviousely work in an area in which security does not seem to be an issue. As I am agitating within the infrastructure of a bank, this is surely an issue, take this for granted. The revision department would fire me immediately if I would be inattentive about this matter.
But if this does not apply for you, you don't have to bother, you are absolutely right. Don't care.
Greetz, Doc
apology to homesick123, my bad mate.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Thomas Heller |
last post by:
I want to append/insert additional data to an xml file.
Context: I use gccxml to parse C header files. gccxml creates an xml
file containing all the definitions from the header files. The xml...
|
by: dmiller23462 |
last post by:
Hey guys....
I put an error-handling in my page and have it posted at the complete
end of the code, see below(when people were putting in 's I was
getting the delimiter errors). Great, I...
|
by: Don |
last post by:
Hi all,
With regards to the following, how do I append the datetimestamp to
the filenames in the form? The files are processed using the PHP
script that follows below.
Thanks in advance,...
|
by: Jonathan Taylor |
last post by:
I have a large XML file, that is too large to read in to XmlDocument.
I need to append data to this XML file without creating a new file, since I
don't want to have two copies of the large file...
|
by: Michael |
last post by:
I have a data application in a2k that I need to create two fixed width
text files and then combine them to a single file The first file is
header information and the second is transaction data. ...
|
by: tony.collings |
last post by:
I started a thread here :
http://groups.google.co.uk/group/microsoft.public.cmserver.general/browse_thread/thread/29d63077144004a9/c3888efdcb7338f6?hl=en#c3888efdcb7338f6
About creating an Email...
|
by: jasper |
last post by:
How can this be done?
Thanks
|
by: Frank |
last post by:
Hi,
Let's say I have a file named myFile.xml
Within that file I have blocks of data which I'd like to add at different
times during the day.
e.g.
<LogEntry>
|
by: sarada purkait |
last post by:
hii
i have to write into a file from the start and then go on appending to it .. i tried using ( ios::out|ios::app) but by this the file keeps on appending every time i run the program and the...
|
by: ofuuzo1 |
last post by:
Hi,
Is there anyway I can append a new element to an existing xml without
first loading the existing file into a variable, adding the new
element into the variable and saving it by overwriting the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |