Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple log files

Status
Not open for further replies.

BitFuzzy

Technical User
Jun 8, 2001
343
US
I'm new at perl so please bare with this potential stupid question.

I'm writing (for practice) a simple log analyzer
Parsing and breaking down apache's access_log is no problem, but where I'm stuck is trying to work with mutiple logs (I use logrotate to keep log file sizes down)

I'm currently using:

$data_file="/open(DAT, $data_file) || die("Could not open file!");
@data=<DAT>;
close(DAT);

and everything's fine, right up until I try adding access_log.1, access_log.2 to the mix.

any suggestions?
 
depends on your error message.
1. perhaps you don't have read permission.
2. perhaps it's a binary file.
3. perhaps it's a link.

which array do you use and how you use it.
 
$data_file=&quot;/open(DAT, $data_file) || die(&quot;Could not open file!&quot;);
@data=<DAT>;
close(DAT); --> this works fine

$data_file=&quot;/ /open(DAT, $data_file) || die(&quot;Could not open file!&quot;);
@data=<DAT>;
close(DAT); --> doesn't (as I said I'm pretty new at this)

I've made an array out of the file locations, which worked (sort of) but instead of displaying acculimitave results

normal --
this is an example

it looped the results giving the results for each file seperatly.

abnormal --
this is an example
this is an example

I hope this made sense :\ if not I'll try to be clearer
 
oh.. by &quot;doesn't work&quot; when mutiple files are referenced as in the second example, data from the file listed first is ignored..

if I were getting content totals file1 had 3 listings and file2 had 2 listings, I'd expect a result of 5

In stead I get either 3 or 2 depending on which file is in the second position.

there isn't any errors (yet) and permissions isn't an issue
 
I think (almost certain) that your script opens the first file, writes lines in array, opens the second file and overwrites your array.

the most simple solution could be to write your files in two different arrays, and use the push command to concatenate array.

$data_file1=&quot;/open(DAT1, $data_file1) || die(&quot;Could not open file!&quot;);
@data1=<DAT1>;

$data_file2=&quot;/open(DAT2, $data_file2) || die(&quot;Could not open file!&quot;);
@data2=<DAT2>;

push @data1, @data2
 
I would put the filenames to be processed in an array and process them one by one using a foreach loop.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
yes it will be more powerfull and portable but the process is nearly the same.

&quot;Les cons ça fait n'importe quoi. C'est d'ailleurs à ça qu'on les reconnait&quot; M.audiard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top