Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old October 24th, 2000, 03:45 PM
d0g1e
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How can I process every line in a large log file, starting from the bottom without, sucking it into an array? I tried to use seek but I can't get the proper result.

Any help is appreciated!

d0g1e -- d0g1e@cyberspace.org

Reply With Quote
  #2  
Old October 24th, 2000, 07:59 PM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Austin, TX or the master control
Posts: 231 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 15 sec
Reputation Power: 9
define 'process'. using an array might not be a bad idea if you are reading in one line at a time then doing your logic, then re-initalize the array with the next line. it all depends on what you are trying to do.

Reply With Quote
  #3  
Old October 25th, 2000, 06:36 AM
d0g1e
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
By process i mean looking for looking for an IP adress in that line etc.

But the problem with using arrays is ( i think) that the complete file gets stuffed into the memory, and since the log file is 60MB, there would be a lot of swapping.

Reply With Quote
  #4  
Old October 25th, 2000, 10:34 PM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Austin, TX or the master control
Posts: 231 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 15 sec
Reputation Power: 9
no dude, you don't store the whole file into an array. rather you read one line at a time into the array. for example if i have a file and i want to read each line of it and store it into an array i can do the following. this is kind of a crude example of how to take the password file and store each section of each line in an array. but note that only one line of elements is 'stored' per pass. do whatever code you need within the while loop.

#!/usr/local/bin/perl


open(LOG, "/etc/passwd");

while (<LOG> ){
chomp($_);
@r = split(/:/,$_);
foreach $element (@r){
print $element . "n";
}
}



Reply With Quote
  #5  
Old October 26th, 2000, 05:02 AM
d0g1e
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thanks, I used arrays the wrong way eg sucking the contents of the log into the array, then doing a while loop with the array and so on.

Still one question, how do i start from the bottom of the file?

Reply With Quote
  #6  
Old October 26th, 2000, 09:47 AM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Austin, TX or the master control
Posts: 231 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 15 sec
Reputation Power: 9
if this is for the apache log files, then use this line before the previous code:

`cat access_log | sort -r > access_log.2`


Reply With Quote
  #7  
Old October 26th, 2000, 11:01 AM
d0g1e
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Is reversing a logfile the only way to start reading from the bottom? I would think perl had some clever command to do this.

Reply With Quote
  #8  
Old October 28th, 2000, 02:29 PM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Austin, TX or the master control
Posts: 231 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 15 sec
Reputation Power: 9
yes, you can reverse the values in the array by using the reverse function...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Processing large log files without using arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway