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

Explain strftime() function in perl?

679


There are some duplicate entries in an array and you want to remove them. How would you do that?

676


How do you you check the return code of a command in perl?

726


How to read a single line from a file in perl?

709


What is cpan in perl?

701






Explain perl. When do you use perl for programming? What are the advantages of programming in perl?

632


Explain socket programming in perl?

660


Differentiate between c++ and perl.

745


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

735


When do you use perl programming?

720


How to prevent file truncation in perl?

674


Where do we require ‘chomp’ and what does it mean?

669


You want to print the contents of an entire array. How would you do that?

698


Which has highest precedence in between list and terms? Explain?

612


What does redo statement do in perl?

743