1. To create a file and write in to the file
Program:
To create a file and write in to the file
open(DATA, ">myfile.txt"); print"Enter String:";
$my_text=<STDIN>;
print DATA $my_text;
close(DATA);
print"\n\t >>>>Data succcesfully store in file.";
Expected O/P:
Enter String:I love Programming.
>>>>Data succcesfully store in file.
2. To append data to the existing file.
Program:
open(DATA, ">>myfile.txt");
print "Enter String to append in Existing file:";
$my_text=<STDIN>;
print DATA $my_text;
close(DATA);
print"\n\t >>>> Data succcesfully store in file.";
Expected O/P:
Enter String to append in Existing file: Hello
>>>> Data succcesfully store in file.
3. To read a file
Program:
open(DATA, "<myfile.txt");
while(<DATA>)
{
print "$_";
}
close(DATA);
Expected O/P:

0 Comments
Post a Comment