CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Matching part of a split

 



xcom
stranger

May 24, 2001, 12:48 PM

Post #1 of 2 (763 views)
Matching part of a split Can't Post

I need some help again guys!

I have (lets call it) "part2" which I was working on before which is:
---------------------------------------------------------------------------
my $percent;
foreach $refer (sort sort_ref keys %referer) {
if ($referer{$refer} >= $referer_min) {
$percent = sprintf ("%.2f",($referer{$refer}/$total*100));
print " <tr>\n <td width=\"15%\">$referer{$refer} </td>\n <td width=\"5%\">$percent\% </td>\n";
if ($refer eq "-") {
print " <td width=\"80%\">NO REFERER</td>\n </tr>\n";
}
else {
print " <td width=\"80%\"><a href=$refer target=top>$refer</a></td>\n </tr>\n";
}
}

}

print "</table>";
---------------------------------------------------------------------------
this is printing out number of hits,percent of total hits and referring url for each referer into a table from data stored in a log file like this:
a201&http://www.excite.com
a201&http://www.yahoo.com
a202&http://www.altavista.com
a202&http://www.excite.com

and is defined in "part 1" like this:
---------------------------------------------------------------------------
open(DATA,"$log_file");
@lines = <DATA>;
close(DATA);
$total = @lines;
foreach $line (@lines) {


{
if ($line =~ /(.*)&(.*)/) {
$id =$1;
$referer = $2;
$referer{$referer}++}}}
---------------------------------------------------------------------------
all this is working nicely. Problem is I want part 2 to be done only for a $match like this:
---------------------------------------------------------------------------
foreach $match (@matches) {
my $percent;
foreach $refer (sort sort_ref keys %referer) {
if ($referer{$refer} >= $referer_min) {
$percent = sprintf ("%.2f",($referer{$refer}/$total*100));
print " <tr>\n <td width=\"15%\">$referer{$refer} </td>\n <td width=\"5%\">$percent\% </td>\n";
if ($refer eq "-") {
print " <td width=\"80%\">NO REFERER</td>\n </tr>\n";
}
else {
print " <td width=\"80%\"><a href=$refer target=top>$refer</a></td>\n </tr>\n";
}
}

}
)
print "</table>";
---------------------------------------------------------------------------
Right now,in Part 1,the script is spltting each line (regardless of a match) and assigning $id and $referer but what I need it to do is Say I have partner a201 log into this script like this:
/stats.cgi?a201................then i want the script to compare $ENV{'QUERY_STRING'} with the lines in the logfile and match the $id part of the lines which look like a201&http://www.excite.com
once its matched each line on the basis of $id,i want it to call those matching lines (but the full line with each part) $match

then I will split $match to be used for part 2,so script will only be writing referring URLS and number of hits foreach $match

So to do that I will revise "Part 1" to look like this:
---------------------------------------------------------------------------

@matches = $match; (is this line right after establishing $match???
close(DATA);
$total = @matches;
foreach $match(@matches) {


{
if ($match =~ /(.*)&(.*)/) {
$id =$1;
$referer = $2;
$referer{$referer}++}}}
---------------------------------------------------------------------------
So basically what I need to know is how to establish $match on basis of $ENV{'QUERY_STRING'} and the first part of log lines (a201&http://www.excite.com) and then take both parts of those matches ($match) into "Part 1" above to then split only the matches into $id and $referer to be used for "Part2" and im not sure if the first line of 'Part 1" (@matches = $match; )is going to be correct after establishing $match

I have gone over and over this and am just not sure how to tell the perl I want to do this! Can anyone help?
Thanks,
xcom



xcom
stranger

May 24, 2001, 2:21 PM

Post #2 of 2 (755 views)
Re: Matching part of a split [In reply to] Can't Post

Geez.....I cant believe it! definately a case of trying to make things too complicated.

This was so easily solved simply by replacing
if ($line =~ /(.*)&(.*)/) with
if ($line =~ /($n1)&(.*)/)

$n1 being $ENV{'QUERY_STRING'}

I guess I was just trying to make it too complicated!


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives