1)Checking the file existence:
Program Code:
#! /Perl/bin/perl
unless(open(IN, "abhi3.txt")) {
if(-e "abhi3.txt")
{
die ("file can't be opened");
}
else
{
die("File doesn't exist");
}
}
print("File Exist!!!!!!!!!!!");
Output:
2)File Reading:
Program Code:
#! /Perl/bin/perl
if(open(FILE,"abhi.txt"))
{
$line=<FILE>;
while($line ne "")
{
print($line);
$line=<FILE>;
}
}
else
{
print("Can't open the specified file");
}
Output:
3)File Reading using Array
Program Code:
#! /Perl/bin/perl
unless (open(FILE, "abhi.txt")) {
die ("cannot open input file\n");
}
@array=<FILE>;
print("@array");
Output:
4)File Writing:In this program i am reading the contents from file abhi and writing that content to another file abhi1.
Program Code:
#! /Perl/bin/perl
unless (open(IN, "abhi.txt")) {
die ("cannot open input file\n");
}
unless (open(OUT, ">abhi1.txt")) {
die ("cannot open output file\n");
}
$line=<IN>;
while($line ne "")
{
print OUT ($line);
$line=<IN>;
}
print("Written Successfully");
Output:
5)File Merging:Int this program i have read the contents of abhi and abhi1 file and then merged it.
Program Code:
#! /Perl/bin/perl
unless (open(IN, "abhi.txt")) {
die ("cannot open input file\n");
}
unless (open(IN1, "abhi1.txt")) {
die ("cannot open output file\n");
}
$line=<IN>;
$line1=<IN1>;
while($line ne " " || $line1 ne " ")
{
if($line ne " ")
{
print ($line);
$line=<IN>;
}
if($line1 ne " ")
{
print ($line1);
$line1=<IN1>;
}
}
Output:
Program Code:
#! /Perl/bin/perl
unless(open(IN, "abhi3.txt")) {
if(-e "abhi3.txt")
{
die ("file can't be opened");
}
else
{
die("File doesn't exist");
}
}
print("File Exist!!!!!!!!!!!");
2)File Reading:
Program Code:
#! /Perl/bin/perl
if(open(FILE,"abhi.txt"))
{
$line=<FILE>;
while($line ne "")
{
print($line);
$line=<FILE>;
}
}
else
{
print("Can't open the specified file");
}
Output:
3)File Reading using Array
Program Code:
#! /Perl/bin/perl
unless (open(FILE, "abhi.txt")) {
die ("cannot open input file\n");
}
@array=<FILE>;
print("@array");
4)File Writing:In this program i am reading the contents from file abhi and writing that content to another file abhi1.
Program Code:
#! /Perl/bin/perl
unless (open(IN, "abhi.txt")) {
die ("cannot open input file\n");
}
unless (open(OUT, ">abhi1.txt")) {
die ("cannot open output file\n");
}
$line=<IN>;
while($line ne "")
{
print OUT ($line);
$line=<IN>;
}
print("Written Successfully");
Output:
5)File Merging:Int this program i have read the contents of abhi and abhi1 file and then merged it.
Program Code:
#! /Perl/bin/perl
unless (open(IN, "abhi.txt")) {
die ("cannot open input file\n");
}
unless (open(IN1, "abhi1.txt")) {
die ("cannot open output file\n");
}
$line=<IN>;
$line1=<IN1>;
while($line ne " " || $line1 ne " ")
{
if($line ne " ")
{
print ($line);
$line=<IN>;
}
if($line1 ne " ")
{
print ($line1);
$line1=<IN1>;
}
}
Output:
0 comments:
Post a Comment