Catriona Pure Scents <[EMAIL PROTECTED]> wrote:

: Hi guys,
: 
: Needing a little help with adjusting the data a log file reads to.
: 
: It goes like this currently....
: @env_vars = keys(%ENV);
: 
: foreach $variable (@env_vars)
: {
: $log_entry .="$ENV{$variable}\|";
: }

    There is no need to escape '|' in a double quoted string.

    This is equivalent to the loop, though I don't know why the
extra '|' at the end would be wanted.

my $log_entry = ( join '|', values %ENV ) . '|';


: I am wanting to change this to include $http_referrer

    If http_referer has anything in it it will be included
already.


: So,I am presuming that I should be doing this:
: 
: foreach $variable (@env_vars)
: {
: $log_entry .="$ENV{'http_referrer"}\|$ENV{$variable}\|"; }

    There is a typo in there.

    $log_entry .="$ENV{http_referrer}|$ENV{$variable}|";
}

: Is this correct??

    My first thought was: What happened when you tried it? Then
I wondered what you meant by correct. In my mind, even after
fixing the typo this is incorrect.

    You are defining every other pipe separated field with the
referrer. At some point, assuming the referrer is defined, there
may be three such fields in a row. I don't think that is
really what you want. This looks more like it:

my $log_entry = join '|', values %ENV );


    The next thing I wondered was whether you were aware that
newlines are embedded in at least one Apache field
('SERVER_SIGNATURE'), thus $log_entry won't be one line in
the log and won't be able to be retrieved as one line.


    Here's a script that generates $log_entry with newlines
("\n") instead of pipes ('|').

#!/usr/bin/perl

use strict;
use warnings;

use CGI;
my $q = CGI->new();

# bold the referrer if present
$ENV{http_referer} = $q->b( $ENV{http_referer} )
                           if exists $ENV{http_referer};

my $log_entry = join "\n", values %ENV;

print
    $q->header(),
    $q->start_html(),
        $q->pre(
            qq|Referrer (if any): "$ENV{http_referer}"\n|,
            $log_entry,
        ),
        $q->br(),
        $q->a( { href => $q->url() }, 'again' );
    $q->end_html();

__END__

    Type the url into the browser address bar the first time.
The second time, click the again link. When I tried it on my
local system (Apache on Windows) I got a referrer only after
clicking the link.

    Notice that the referrer is included in the list when it
is defined.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to