K
ko
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.
[snip explanation of hoework specs, etc]
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.
It may be hard to sort out all the advice offered when it seems like
you're getting flamed solely for this reason, but you're not helping
yourself. What I mean is that people have offered *good* advice, which
has been ignored in your *posted* code.
^^^^^^^^^^^^^^^^while <$addr> { # reads input from client
Here's an example. As Tad pointed out in your quoted text, this is not
Perl code. It won't compile, try it. I'm assuming you have read the
posting guidelines (http://mail.augustmail.com/~tadmc/clpmisc.shtml), so
try and put yourself in the shoes of the regulars/experts. They are busy
people and take time every day to offer advice to many people. Its only
natural that you may get flamed or ignored if you can't at least show
some kind of effort - at the very least post code that compiles.
Granted, everyone makes mistakes, but in this case you did it at least
twice, even after someone took the time to point it out. Actually, its
obvious that instead of copy/paste, you're typing in your code snippets:
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
The above code won't pass anything into the array because, as is, it
won't compile. Since you're gettting results the code you are running
must be different than what was posted above. Your code is probably
something like this:
while (<$addr>) {
print $_;
@lines = <$addr>;
...
}
Which, if you wanted to assign all lines in the file to an array, should
be done like this:
@lines = <$addr>;
'perldoc perlop', - 'I/O Operators' for details.
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;
}
************
And this won't compile either.
And none of what has been written is meant to be critical. What you need
to understand is that the people helping you can't read your mind, and
that no one can help you if you don't first help yourself (use warnings,
use strict, etc). Once again, put yourself in the shoes of the regulars.
Would you want/be able to sort through a bunch of incomprehensible
code that doesn't even compile? Its expected that you put some kind of
effort in what you post *before* you post, and more simply, just common
sense/courtesy. On a more positive note, I agree with your opinion that
everyone learns differently - I think its hard for some people to
remember what its like learning your first programming language
HTH - keith