I want to add a line to top and bottom of the file. I can do it following way.
open (DATA, \"
Three answers have been given that perpetuate the very bad practice of:
open(FILE,"
Not only that, the code is broken since you are not opening the file for writing but for reading.
When an open fails, you can tell the user why it failed. Please get in the habit of including $! in the error message. Also, use the three argument form of open
to separate the mode from the name:
my $path="file";
open my($fh), '>', $path or die "$path: $!";
(This does not answer your question, but I'm making it an answer rather than a comment for added emphasis and so that I can review it as it is a rather lengthy spewing forth.)