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 / prabhakaran m

## Go to that Directory
my $file_output = "output";

open(OUTFILEHANDLE,">$file_output") || die "Unable to open
the file : $file_output";

foreach my $input_file (`ls -1`) {
open(INFILEHANDLE,"$input_file") || die "Unable to
open the file : $input_file";
while (<INFILEHANDLE>) {
print OUTFILEHANDLE $_ if (/print header/);
}
}

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is Chop & Chomp function does?

751


Explain the difference between declarations of 'my' and 'local' variable scope in perl?

690


how to create a flat file database as shown below s.no name age city phone 0 hema 22 Calcutta 4312542 1 hema 21 Bangalore 2344345 2 ganesh 25 delhi 2445454 3 kartik 45 pune 4312121 4 santosh 25 Hyderabad 2254231 5 kumar 25 mysore 2344567 6 gita 34 mangalore 6532123 7 gita 32 pune 2213456 Q1.print the details of the person who r from bangalore q2.Replace the city name managlore to pune q3.prints no of person having name gita and hema q4.print how many are of age 25.

1838


Explain chomp?

678


Why does Perl not have overloaded functions?

714






What does this symbol mean '->'?

684


how to get back up from private character editor which is saved in the format of .udf

2035


How will you get the count of parameters passed to a perl subroutine?

691


How can information be put into hashes?

696


List the files in current directory sorted by size ?

651


what is the main function of fork() in cgi programming?

727


Explain grooving and shortening of arrays and splicing of arrays?

654


Why do you use Perl?

731


What happens when you return a reference to a private variable?

732


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

677