[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Peter's Perl Predicament



At 12:33 PM 2/12/96, Peter wrote:
>if ($line=~/GET\shttp:\/\/www2.waikato.ac.nz:81$bas"\s|GET\s$bas\s/)
>    {
>++$a;
>         {
>          if ($line=~/nz\s/)
>                {
>                    ++$d;              #New Zealand
>                }
>          if ($line!~/nz\s/)
>                {
>                       ++$c;           #international
>                }
>          }
>     }
>}
>}
>#################
>
>However, Matthias said this :-
>
>>instead of
>>reading a fixed file of Bas'es, you could simply grep the actual URLs i.e.
>>
>>
>>if (/GET (http://[^/]+)?(\S+)/) {
>>    if (.nz) {
>>        $NZHits{$2}++;
>>    } elsif (.au) {

>This is the bit I don't understand, I've tried various things without success.
>I am a complete beginner, and have no programming background. I've started
>this Web Site and all of a sudden the logs are each several hundred pages
>long (and growing !),
>and so I have been learning Perl over the last few weeks so that I can
>extract the necessary stats from the logs. If I could achieve what Matthias
>has outlined it would make life a lot easier. I have searched high and low
>for the answer but all the documentation I can find tells me some but not
>all of what I need to know. What I need is for some kind soul to take me
>step by step through the process of "grepping the actual urls" so that I
>can see how it's done.
>I have ordered 'Learning Perl' from  O'Reilly's but it hasn't arrived yet.
>If anyone can spare the time to help me out here I'd be very grateful.

Ok.  Get yourself a UNIX box for a minute, and at the command line type
"man grep".  Read the pages for it.  If you need it mailed to you, i'll
mail a copy.  Basically, grep is a unix utility to do VERY heavy duty
pattern matching - you can do ALMOST any matching with GREP - its like a
find/replace dialog box in an application.  What Matthias did was have it
do a grep (the part between // in the if test), to have it match ANY line
that contains "GET " (and some other testing, as I don't remember ALL of my
grep statements), in which case it will add to the appriate hit counter.
The $2 used as the key is part of the actual thing matched - in MacPerl
type "Help", and then get help on the command "s".  It should explain that
$2 thing in there.  Sorry I can't help beyond that, but basically he is
testing (in a complex manner) for url's.  (Also, s and grep commands in
perl have some nice docs for greping.)

Shawn.

######################################################################
#  In Jersey: The Digital Information Network of the Garden State    #
#      Freelance HTML/Graphics/Programmer                            #
######################################################################
#             http://puma.bevd.blacksburg.va.us/~spearce/            #
# http://nj5.injersey.com/~spearce/  ###  http://www.injersey.com/   #
######################################################################