#!/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 () { # 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 that 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/insurance/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" "-" "marketing.ge.com" 16/Jan/2005:00:00:40 -0500 "GET /portal/site/transportation/menuitem.8c65c5d7b286411eb198ed10b424aa30/ HTTP/1.1" 200 7596 0 "http://geae.home.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_portletview.html HTTP/1.1" 200 7240 0 "http://marketing.ge.com/portal/site/insurance/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" "-" "marketing.ge.com" #### print $businesses{$1} $_; #yields: #Scalar found where operator expected at C:\t.pl line 36, near "} $_" #(Missing operator before $_?)