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 ();

In reply to Dereference a reference to a file handle created with IO::File by dgdriscoll

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.