in reply to Reduce the time taken for Huge Log files
#!/usr/bin/perl use strict; use warnings; use FileHandle; # create a hash of businesses and their target files my %businesses = ( "corp.home.ge.com" => "new_corp_home_ge_com.log", "scotland.gcf.home.ge.com" => "new_scotland_gcf_home_ge_com.log", "marketing.ge.com" => "new_marketing_ge_com.log", ); #loop the data while (<DATA>) { # check if we have a line that contains a http:// address # and store that in $1 #\" is just to prevent editor from screwing syntax higlight if ( m-http://([^/\"]+)- ) { # do we have a entry in the hash for that business if ( $businesses{$1} ) { #yes. so create a filehandle in the hash for writing to th +at unless ( ref $businesses{$1} ) { my $fh = new FileHandle; $fh->open (">$businesses{$1}"); $businesses{$1} = $fh; } #print to the business' filehandle $businesses{$1}->print ($_); } else { #no so emmit a warning warn "unknown business in logfile"; } } } __DATA__ 16/Jan/2005:00:00:40 -0500 "GET /ge/ige/1/1/4/common/cms_portletview2. +html HTTP/1.1" 200 1702 0 "http://marketing.ge.com/portal/site/insura +nce/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" "-" "marke +ting.ge.com" 16/Jan/2005:00:00:40 -0500 "GET /portal/site/transportation/menuitem.8 +c65c5d7b286411eb198ed10b424aa30/ HTTP/1.1" 200 7596 0 "http://geae.ho +me.ge.com/portal/site/transportation/" "Mozilla/4.0 (compatible; MSIE + 5.5; Windows NT 5.0)" "-" "geae.home.ge.com" 16/Jan/2005:00:00:41 -0500 "GET /ge/ige/26/83/409/common/cms_portletvi +ew.html HTTP/1.1" 200 7240 0 "http://marketing.ge.com/portal/site/ins +urance/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" "-" "ma +rketing.ge.com"
??print $businesses{$1} $_; #yields: #Scalar found where operator expected at C:\t.pl line 36, near "} +$_" #(Missing operator before $_?)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reduce the time taken for Huge Log files
by pr19939 (Initiate) on Mar 18, 2005 at 15:04 UTC | |
by holli (Abbot) on Mar 18, 2005 at 15:23 UTC | |
by Random_Walk (Prior) on Mar 18, 2005 at 15:24 UTC | |
|
Re^2: Reduce the time taken for Huge Log files
by nobull (Friar) on Mar 18, 2005 at 18:00 UTC | |
by holli (Abbot) on Mar 18, 2005 at 18:04 UTC |