Hi All, I have essentially 2 questions.
I am looking for a more efficient way to match a particular string starting at the bottom of an application log file. According to the Perl Cookbook "Reading a File Backwards by Line or Paragraph", (8.4), you need to read all the lines into an array in reverse order: @lines= <FILE>; foreach $line (@lines) { # Do something with $line } This works fine. However, I generally have to look at 8-9 different log files, each at an average of 10 - 50 megs in size. Since I only want to match the first occurrence of the particular string I'm looking for, I decided against using "grep" but instead, something like this: @lines =<FILE>; foreach $line (@lines) { if ($line =~ /Error/ ) { print "Error Message is $line"; last; } } This seems to work OK, except I have some cases where the log files can reach 100-200 megs in size, and I start to see a serious hit on performance. So I says to myself, Kenny-boy, you don't need the whole log, just grab the last 500 lines or so, then search on that. But first in order to get the "right" log to search (there can be several different ones for each application a day), I need to get the latest log file. To do this a use the following method: $wanted_log = qx(ls -rt /usr/local/error_logs/app-*$log_date.log | tail -1); The log files have the following format:app-Month-ddhhmm.log. This also works fine. Interesting enough, I thought "qx" was the same as using back ticks `, but the back ticks do not interpolate the variable, where the "qx" does. This leads to my second problem. The next line of the script creates the smaller version of the log. Thus: system ("tail -500 /usr/local/error_logs/$wanted_log >/tmp/half_log"); Instead of creating the half_log file, the output is printed to the screen (STDOUT) instead. I was using "glob" instead of "qx" above to get the file name, but it was not returning the latest one by date, only alphabetically. However, the system command was not printing out to the screen. If you made it this far, the questions again: 1) What is the most efficient or quickest way, performance wise, to search from the bottom of the file for the first occurrence of a string. 2) Why does the system command print to STDOUT when using "qx" in place of "glob" instead of creating the file? -- Ken Hammer Information Technology Central Services University Of Michigan [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]