Hi, everything else seems to work if I manually insert file names instead of using hash values but everything I have tried on lines 40,44 &47 gives me a string instead of a file handle. What am I doing wrong? thanks, Dave Driscoll
#!/usr/bin/perl -w #ad_sort.pl #in ~/logs take paydirt.log as input #for each item in the ads hash, #search for a match for 'GET /bookstore/'+ads key #when a match is found, write that and all following lines to #ads key value . #until a string containing '####' is found then stop writing #keep reading until next match or EOF use IO::File; use strict; use diagnostics; my $do_write = 'no'; open(MYINPUTFILE, "<paydirt.log") || die("$!"); my $western_lore_ad1 = IO::File->new("> ad_logs/western_lore_ad1.log") +; my $western_lore_ad2 = IO::File->new("> ad_logs/western_lore_ad2.log") +; my $western_lore_ad3 = IO::File->new("> ad_logs/western_lore_ad3.log") +; my $native_ad1 = IO::File->new("> ad_logs/native_ad1.log"); my $native_ad2 = IO::File->new("> ad_logs/native_ad2.log"); my %ads = ('western_lore.php?ad=n1'=>$western_lore_ad1,'western_lore.p +hp?ad=n2'=>$western_lore_ad2,'$western_lore.php?ad=n3'=>$western_lore +_ad3,'native.php?ad=n1'=>$native_ad1,'native.php?ad=n2'=>$native_ad2) +; my @ad_strings = keys $ads; my(@lines) = <MYINPUTFILE>; foreach (@ad_strings){ my $this_ad = $_; my $clicks = 0; foreach my $line (@lines){ if ($line =~ m/GET \/bookstore\/\Q$this_ad/){ $do_write = 'yes'; $clicks++; } if ($do_write eq 'yes'and $line =~ m/###/){ print $ads{$this_ad} "$line\n";#this should print to one of the +files referenced by IO::File on lines 21-25 $do_write = 'no'; } if($do_write eq 'yes' ){ print $ads{$this_ad} $line;#ditto } } print $ads{$this_ad} "clicks = $clicks \n";#ditto } close (MYINPUTFILE); $western_lore_ad1->close; $western_lore_ad2->close; $western_lore_ad3->close; $native_ad1->close; $native_ad2->close; exit ();
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |