!novice alert! pardon me, I realize this is more than likely a very simple question, however, I cannot (for the life of me) figure out why it doesn't work. I want to store the pattern of the apache log and IIS log format in a regex type thing ($apache_log and $iis_log). I would also like to store a string ($docuement and $document2) that happens to be something I am looking for in the document (i.e. index.html or a specific query). but my silly little script doesn't appear to work very well, ANY help would be greatly appreciated. here is some code to do roughly what I am thinking:
#!/usr/bin/perl -w $apache_log="/(.*)\s+-\s+-\s+\[(\d+)\/(\w+)\/(\d+):(\d+):(\d+)/"; # Hmm I know there is a better way to parse this $iis_log="/(\d+):(\d+):(\d+)\s+(\d+\.\d+\.\d+\.\d+)\s/"; $document="/report.html\?/"; $document2="/secret.html\?/"; # open the log file - the log file we want to check out open(LOG, "<$ARGV[0]") || die("Could not open $ARGV[0] : $!"); # open our Report file - the file we will write out report to open(REPORT, ">$ARGV[1]") || die("Could not open $ARGV[1] : $!"); while(<LOG>){ if($document){ ($ip, $day, $month, $year, $hr, $min) = $_ = $apache_log; # if I was + using IIS I would set this to $iis_log, is there a better way? $totaldoc++; print REPORT "Access on doc1 from: $ip on $month $day at $hr:$min\n" +; } elsif($document2){ $totaldoc2++; print REPORT "Access on doc2 from: $ip on $month $day at $hr:$min\n" +; } } print REPORT "Total doc1: $totaldoc\n"; print REPORT "Total doc2: $totaldoc2\n"; close(LOG); close(REPORT);

In reply to question about regex and using a scalar variable to store/call it by Anonymous Monk

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.