Karyn Williams am Donnerstag, 29. März 2007 20:27: [snip] > It varies greatly. Often one or two. Sometimes 70. The size of the files is > fairly substantial: > > -rw-r--r-- 1 root other 249595095 Sep 1 2006 maillog.200608 > > I am getting Out of memory errors while running the script. [snip] > I have hashed and slurped files in other scripts. I could try it here and > see what happens. [snip] > >> >> open MAILLOG, > >> > >> "/export/home/archives/maillog.$flist[1]" or die > >> > >> >> "couldn't open maillog.$flist[1] : $!\n"; > >> >> if ($count = grep /user=$k/o, <MAILLOG> ) { > >> >> print "$k checked mail $count times in > >> >> maillog.$flist[1].\n"; next ; > >> >> } else { > >> >> close MAILLOG; [snip]
Hello Karyn (Didn't quite got the overview: Formatting, combined top/inline posting, unstripped postings. So the following may be inappropriate) Try to read the logfiles line per line (instead of slurping the whole log file into memory), using a while loop, along the lines: while (<MAILLOG>) { # handle log line (contained in $_) here } # handle result of parsing the whole file here This will use minimal memory resources. > # ./tt.pl karyn smurphy root > karyn checked mail 2864 times in /var/adm/maillog. > smurphy checked mail 2864 times in /var/adm/maillog. > root checked mail 2864 times in /var/adm/maillog. > # > > Yes, it goes to the next arg but as you can see, it returns the same count > for each subsequent arg. The reason for this probably is the o modifier in /user=$k/o regexes: this will fix the value of $k within the regex. Try to define a precompiled regex every time $k changes - this will compile a regex once for every different value of $k: # value assigned to $k here my $regex=qr/user=$k/; # ... $variable=~/$regex/ && count++; This is the alternate way to speed up matching. Dani -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/