Monday, July 11, 2011

Reading a File and printing to STDOUT Perl

content of hello.dat:

hello how are you
wonderful beautiful
great
award great
awesome

content of Perl file:

perl_file1.pl
open(FILE,"<hello.dat");
@lines=<FILE>;      
close(FILE);
foreach(@lines)
{
chop;
print;   # it is same as print $_;
print "\n";
}

output:

G:\perl_programs>perl perl_file.pl
hello how are you
wonderful beautiful
greataward great
awesom
G:\perl_programs>

No comments:

Post a Comment