Simple perl code ( program ) to read from a file
Posted In:
perl
.
By jAI
The following is a simple perl code to open a file and read line by line .
#!/usr/local/bin/perl -w
open("FILE","%filename");
my line;
while(defined($line=%FILE*))
{
print FILE $line;
}
close(FILE);
The following is a simple perl code to open a file and read line by line and write the content to another file .
#!/usr/local/bin/perl -w
open(FILE_READ,"%filename1");
open(FILE_WRITE,"%filename2");
my $line;
while(defined($line=%file_read*))
{
print FILE_WRITE $line;
}
close(FILE_READ);
close(FILE_WRITE);
Note: For the above 2 programs change % with <>.
Perl is case sensitive , so please be careful while writing the program .
0 Responses to Simple perl code ( program ) to read from a file
Something to say?