use Tie::File;
tie my @lines, 'Tie::File', 'myfile.txt' or die 'tie failed';
unshift @lines, "a new line\n";
untie @lines;
| [reply] [d/l] |
Puh-lese!!
- Do you care what's in the added line? (or would a solution using random content work/be required?)
- How are you defining line?
(A collection of chars followed by a \n? ...and, then how are you defining "\n"? or maybe... a string of not_more_than 65|72|80 chars?) ...And oh, yeah, we may need to know encoding, ...
- To what sort of file are you adding this line: text or binary?
- OS?
And WHAT HAVE YOU READ? WHAT HAVE YOU TRIED?
Suggest you read How do I post a question effectively?, perldoc, the FAQs here, and maybe search for "prepend" "filehandle" or....
Enough.
Here's a simple, less sarcastic reply: We don't do other people's homework (not "knowingly" anyway) and we greatly prefer to spend time answering questions where post shows that the poster has made some effort (eg, has written and posted code; has provided a clear and unambiguous indication of the expected/desired results, etc.)
So go ahead and make our day. Demonstrate some effort and you'll find rich rewards here. | [reply] |
You Sarcastic Wretch!
No! this was not homework. It was merely a simple question
of which knowing not where to begin.
It is your type of high and mighty demeanor and sarcasm that scares off those who indeed may need help the most.
In the time you wasted in spewing out sarcasm you likely could have used your energy in coming up with an effective response such as the more noble monk tlm did in his response. Often times the "lowliest monk"(s), as tlm referred to himself have the best responses. Thanks TLM. Perhaps a lesson of humility is in order for those who think that they are too high and mighty giving sarcasm instead of an effective more useful response.
| [reply] |
| [reply] |
% echo "See spot run" > newfile
% cat origfile >> newfile
% mv newfile origfile
Voila! | [reply] [d/l] |