hello how are you
wonderful beautiful
great
award great
awesome
Content of the perl file:
open(FILE,"+<hello.dat");
# "+<" option has to be used for read and writing to the file
@lines=<FILE>;
foreach(@lines)
{
chop;
print; # it is same as print $_;
print "\n";
}
print FILE "\n"."karthik";
close(FILE);
Output Execution:
G:\perl_programs>perl perl_file.pl
hello how are you
wonderful beautiful
great
award great
awesom
G:\perl_programs>
Content of the hello.dat file after execution:
hello how are you
wonderful beautiful
great
award great
awesome
karthik
how to write "karthik" in between the lines of "award great"and "awesome".
ReplyDelete