Tad McClellan said:
John said:
open DATA, ">>test.xml"; # append to file
You should always, yes *always*, check the return value from open():
open DATA, '>>test.xml' or die "could not open 'test.xml' $!";
print DATA @lines [0]; # print the first element in the array
You should enable warnings when developing Perl code!
while <$addr> { # this is the input
That is not Perl code. You are wasting the time of *thousands* of
people around the world because you cannot be troubled to
provide actual code!
That's it. You've used up all your coupons.
So long.
My apologies for not being able to reply to everyone. This would just make
this thread into a spaghetti. This is not a direct reply to Tad's last post
but is intended to cover the last few posts from all of you. Whilst I may
not agree with everyone's opinions I respect your views.
Just to confirm, our instructor did not ban anyone from using newsgroups. We
were given a task and are supposed to complete it. How we go about doing it
is up to us. There was no list of resources that we should or should not
refer to.
For those of us who write books, not everything is covered in them and hence
there exists a need for forums, newsgroups, mailing lists etc. Furthermore,
such resources are best utilised when a specific problem or need arises.
Everyone learns in different ways. Some may only need to read a description
of what a car is to be able to understand its purpose. Others may need to
actually drive one. Some ppl read a book from start to finish, others skip
around to parts of interest or on a need to know basis.
I am very much against plagiarism and would not expect anyone to give me an
answer. Consequently, I had no problem saying that I'm working on a homework
related task. Mind you, this is but a component of it and I have tried to
word it in such a way as not to give myself an outright answer. I have in
the past read some of your columns Randal [not to mention the books]. I just
didn't take it too well with your accusations. Oh, and I doubt I'll be
applying for work where you are - it's not my area of interest.
So pls feel free to flame me when my search for clues is wasting your time
cause the code examples I provide are irrelevant but spare yourself from
judging the way in which I do my search. There will be those who support the
Monarchy and others who support the Republic. I'm probably somewhere in the
middle.
Anyway, that's just my opinion, I hope I have not offended anyone.
Back to the code for those who are still interested.
I am only including the below code examples as they seem to be the only ones
which are relevant [or maybe that's just my poor newbie judgement].
The below is done using sockets and I have the server and the client working
without a prob. The client passes the correct data to the server and the
server writes it to a file [or most of the data]. So I'm a bit stomped as to
why it's not a 100% correct.
Code extract - server script:
************
sub fileupdate {
open DATA, ">>test.xml" or die "Could not open test.xml $!\n"; #
open file file to append data to
print DATA @lines;
# add the data stored in the array
close DATA;
# close the file
}
....
....
while <$addr> { # reads input from client
print $_; # this prints to the screen the
first line of the file passed by the client
@lines <$addr>; # I want this array to capture the whole
file passed from the client
}
fileupdate (); # calling function
************
Q: Why isn't line 1 passed into the array?
print $_ echoes line 1 on the server side [so we know it's been received]
and 'cat FILE_B' only shows:
line 2
line 3
Everything was working fine when I only had this:
************
while <$addr> {
open DATA, ">>test.xml" or die "Could not open test.xml $!\n";
print DATA $_;
close DATA;
}
************
For example, 'cat FILE_B' would correctly show:
line 1
line 2
line 3
FILE_A passed by the client has
line 1
line 2
line 3
as its contents.
Does this make sense?
Thanks.