i have a folder called 'error' and in that, i have error log
files which are generated by the build,
now i want to findout the string 'error' from each log
file and that error has to be copied into the another file
called 'analysis'.
how do you do this in perl?

Answer Posted / vipul dalwala

$infile = 'errorlog.txt';
$outfile = 'analysys.txt';

open(INFILE,$infile) || die "Unable to Open $infile-$!";
open(OUTFILE,$outfile) || die "Unable to Open $outfile-$!";

while ( <INFILE> ) {
print OUTFILE $_ if (/error/);
}

close INFILE;
close OUTFILE;

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I pass a command line argument in perl?

556


What do you mean by context of a subroutine?

564


What is a perl references?

524


How to close a directory in perl?

498


What is the peculiarity of returning values by subroutines in perl?

486






What is the importance of perl warnings? How do you turn them on?

550


What does last statement do in perl?

527


What is a chop() function in perl?

576


Explain the functioning of conditional structures in perl.

469


what are the two ways to get private values inside a subroutine or block?

510


Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

634


How many ways can we express string in Perl?

540


Explain ivalue in perl?

534


How will you create a file in perl?

523


Can inheritance be used in perl? Explain with the help of an example.

510