php-programmer needs some aute help with a Perl statement
php-programmer needs some aute help with a Perl statement
am 23.07.2006 17:02:04 von Alf Christophersen
In a database system I take care of the php programming and my
colleague takes care og the perl side.
Unfortunately, he is on holidays until about august 17. and the
followinh code snippet don¨t work as aspected. Could any give a quick
and dirty help?
The snippet shows $DISBYT_program as /local/cgi-bin-test when the
string test is not apparent in the string:
if ($_SERVER['HTTP_HOST'] =~ m/"test"/){
$DISBYT_program="/local/cgi-bin/";
}
else {
$DISBYT_program="/local/cgi-bin-test/";
}
What's wrong
(In php
if (strpos($_SERVER['HTTP_HOST'], "test") === false){
$DISBYT_program="/local/cgi-bin/";
}
else {
$DISBYT_program="/local/cgi-bin-test/";
}
Hope someone could help.
Thanx in advance.
Re: php-programmer needs some aute help with a Perl statement
am 23.07.2006 19:30:25 von mlj
Alf Christophersen wrote:
> In a database system I take care of the php programming and my
> colleague takes care og the perl side.
> Unfortunately, he is on holidays until about august 17. and the
> followinh code snippet don¨t work as aspected. Could any give a quick
> and dirty help?
>
> The snippet shows $DISBYT_program as /local/cgi-bin-test when the
> string test is not apparent in the string:
>
> if ($_SERVER['HTTP_HOST'] =~ m/"test"/){
I can see two problems with this:
(1) The test is for whether the substring "test" (*including* the
quotes) is found in the string.
(2) $_SERVER['HTTP_HOST'] refers to an array element where the string
'HTTP_HOST' is used as the index value. Perl tries to evaluate the
string 'HTTP_HOST' as an integer, which fails of course, so array
element $_SERVER[0] gets tested here. I'm not familiar with php but
according to http://www.cs.wcupa.edu/~rkline/perl2php/ the variable
$_SERVER corresponds to the perl environment variable %ENV so this
should probably read $ENV{'HTTP_HOST'} .
> $DISBYT_program="/local/cgi-bin/";
> }
> else {
> $DISBYT_program="/local/cgi-bin-test/";
> }
You could say
if ($ENV{'HTTP_HOST'} !~ m/test/){
$DISBYT_program="/local/cgi-bin/";
}
else {
$DISBYT_program="/local/cgi-bin-test/";
}
or
if ($ENV{'HTTP_HOST'} =~ m/test/){
$DISBYT_program="/local/cgi-bin-test/";
}
else {
$DISBYT_program="/local/cgi-bin/";
}
or
if (!index($ENV{'HTTP_HOST'}, 'test')){
$DISBYT_program="/local/cgi-bin/";
}
else {
$DISBYT_program="/local/cgi-bin-test/";
}
etc.
>
> What's wrong
>
> (In php
>
> if (strpos($_SERVER['HTTP_HOST'], "test") === false){
> $DISBYT_program="/local/cgi-bin/";
> }
> else {
> $DISBYT_program="/local/cgi-bin-test/";
> }
Re: php-programmer needs some aute help with a Perl statement
am 23.07.2006 20:02:52 von mlj
mlj wrote:
> if (!index($ENV{'HTTP_HOST'}, 'test')){
Oops, this should be:
if (index($ENV{'HTTP_HOST'}, 'test') == -1){
Re: php-programmer needs some aute help with a Perl statement
am 23.07.2006 20:21:32 von Alf Christophersen
On Sun, 23 Jul 2006 20:30:25 +0300, mlj
wrote:
>if ($ENV{'HTTP_HOST'} !~ m/test/){
> $DISBYT_program="/local/cgi-bin/";
> }
>else {
> $DISBYT_program="/local/cgi-bin-test/";
> }
>
As I cab see, this worked very well.
Thanx a lot.
I'll also forward your message to my colleague on holidays.