Forum Moderators: coopster & phranque

Message Too Old, No Replies

Removing space from User Agent

         

JAB Creations

3:44 pm on Dec 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm using a statistics script that puts unknown UAs into a seperate unknown page. While the script is supposed to parse spaces as underscores it does not work ... since the script is rather massive I figure the part of the script that I found would just make things easier to work with...

This part of the script funnels unknown UAs into the unknown UA page... it also rewrites the UA ... how do I mod this to replace spaces with unscore?

For example I would want to convert MSIE 6.0 to MSIE_6.0.


# Unknown browser?
if (!$found) {
$_browser_h{'Unknown'}++;
$TmpBrowser{$UserAgent}='Unknown';
my $newua=$UserAgent; $newua =~ tr/\+ /__/;
$_unknownrefererbrowser_l{$newua}=$timerecord;
}
}
else {
$_browser_h{$uabrowser}++;
if ($uabrowser eq 'Unknown') {
my $newua=$UserAgent; $newua =~ tr/\+ /__/;
$_unknownrefererbrowser_l{$newua}=$timerecord;}

rocknbil

6:47 pm on Dec 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jab you need to look into the special meaning of the underscore in context with other characters in Perl. $_ and @_ have special meanings, and sometimes it attempts to interpret _ next to another character as . . . something else.

To answer your question, try

$newua =~ tr/\+/\_/;

or

$newua =~ s/+/\_/g;