From: Pat Rice [mailto:[EMAIL PROTECTED] Sent: Thursday, September 13, 2007 11:14 AM To: Andrew Curry Cc: Chas Owens; beginners@perl.org; [EMAIL PROTECTED] Subject: Re: adding data to a file before it gets regexed
thanks all for the replies, I'm trying to parse log files. so I got a bunch of logs in a directory, put them together and then parse them, I'm trying to keep a reference of the log files, so I know what log they came from, as I'm need to keep the file name to put it in to a another script. I think from what people are suggesting I will have to use hashes, is there any good example log file perl scripts out there? or a good site ? as I'm trying to take the logs that I find interesting and then display them on a web page using html templates Thanks for all the help Pat [>>] Here's a "way" ... Hope this gives you some ideas... SUN83-PRODWEB>more ~/foo #! /usr/local/bin/perl use strict; opendir HERE, '.'; my %logs; my $logs_total; while (my $filenm = readdir HERE) { $logs_total++ if $filenm =~ 'log$'; next unless $filenm =~ '^access_sun83.*log$'; open LOG, $filenm; my $cnt; while (my $logdata = <LOG>) { $cnt++; } close LOG; $logs{$filenm} = $cnt; } close HERE; printf "There are %d logs HERE\n", $logs_total; printf "I processed %d logs\n", scalar(keys %logs); foreach my $filenm (sort keys %logs) { print "There are $logs{$filenm} items in $filenm\n"; } SUN83-PRODWEB> SUN83-PRODWEB>~/foo | more There are 891 logs HERE I processed 141 logs There are 49 items in access_sun83.20070314.log There are 172 items in access_sun83.20070315.log There are 25 items in access_sun83.20070316.log There are 144 items in access_sun83.20070319.log There are 124 items in access_sun83.20070320.log There are 47 items in access_sun83.20070321.log There are 131 items in access_sun83.20070322.log There are 29 items in access_sun83.20070323.log There are 16 items in access_sun83.20070325.log There are 63 items in access_sun83.20070326.log There are 51 items in access_sun83.20070328.log There are 52 items in access_sun83.20070329.log There are 84 items in access_sun83.20070330.log There are 66 items in access_sun83.20070402.log There are 129 items in access_sun83.20070403.log There are 313 items in access_sun83.20070404.log There are 215 items in access_sun83.20070405.log There are 65 items in access_sun83.20070406.log There are 100 items in access_sun83.20070409.log There are 73 items in access_sun83.20070410.log There are 252 items in access_sun83.20070411.log There are 114 items in access_sun83.20070412.log There are 105 items in access_sun83.20070413.log There are 11 items in access_sun83.20070415.log There are 90 items in access_sun83.20070416.log There are 109 items in access_sun83.20070417.log There are 96 items in access_sun83.20070418.log There are 97 items in access_sun83.20070419.log --More-- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/