Below are some examples of formats:
Program Code:
#! /Perl/bin/perl
$~ ="MYFORMATHEADER";
write;
format MYFORMATHEADER=
===========================================
This line contains special character @
"<"
===========================================
.
Output:
Program Code:
#! /Perl/bin/perl
print("Enter a string\n");
@input=<STDIN>;
$str=join("",@input);
$~ ="MYFORMATHEADER";
write;
format MYFORMATHEADER=
======================================================
The input is
@*
$str
======================================================
.
Output:
Program Code:
#! /Perl/bin/perl
print("Enter a string to write it into a file\n");
@input=<STDIN>;
$str=join("",@input);
open(FILE,">abhi1.txt");
select(FILE);
&write_output;
select(STDOUT);
&write_output;
sub write_output{
$~ = "FORMAT1";
write;
}
format FORMAT1=
======================================================
The input is following:
@*
$str
Above lines are written in file named abhi1.txt
======================================================
.
Output:
Program Code:
Output:
Program Code:
Output:
Program Code:
Output:
Program Code:
Output:
Program Code:
Output: