Cagliostro
Programmer
Hi, I have a problem
this is the output:
The value of variables comes from a CGI application, so, I have to know if there was passed some string, some number, some string with spaces or some string with zeroes. How can I test this thing? In each situation what is different than another one, the test is the same, but behavior is different...
Ion Filipski
Code:
use strict;
my $x;
if($x){print("x\n");}else{print("!x\n");}
if($x == 0){print("x == 0\n");}else{print("x != 0\n");}
if($x == "0"){print("x == \"0\"\n");}else{print("x != \"0\"\n");}
if($x == "00"){print("x == \"00\"\n");}else{print("x != \"00\"\n");}
if($x == ""){print("x == \"\"\n");}else{print("x != \"\"\n");}
if($x == " "){print("x == \" \"\n");}else{print("x != \" \"\n");}
if($x == " "){print("x == \" \"\n");}else{print("x != \" \"\n");}
my %xx;
if($xx{'abc'}){print("xx{'abc'}\n");}else{print("!xx{'abc'}\n");}
if($xx{'abc'} == 0){print("xx{'abc'} == 0\n");}else{print("xx{'abc'} != 0\n");}
if($xx{'abc'} == "0"){print("xx{'abc'} == \"0\"\n");}else{print("xx{'abc'} != \"0\"\n");}
if($xx{'abc'} == "00"){print("xx{'abc'} == \"00\"\n");}else{print("xx{'abc'} != \"00\"\n");}
if($xx{'abc'} == ""){print("xx{'abc'} == \"\"\n");}else{print("xx{'abc'} != \"\"\n");}
if($xx{'abc'} == " "){print("xx{'abc'} == \" \"\n");}else{print("xx{'abc'} != \" \"\n");}
if($xx{'abc'} == " "){print("xx{'abc'} == \" \"\n");}else{print("xx{'abc'} != \" \"\n");}
printf("x = {$x}\n");
$x = 0;
printf("x = {$x}\n");
$x = "00";
printf("x = {$x}\n");
$x = " ";
printf("x = {$x}\n");
$x = " ";
printf("x = {$x}\n");
Code:
!x
x == 0
x == "0"
x == "00"
x == ""
x == " "
x == " "
!xx{'abc'}
xx{'abc'} == 0
xx{'abc'} == "0"
xx{'abc'} == "00"
xx{'abc'} == ""
xx{'abc'} == " "
xx{'abc'} == " "
x = {}
x = {0}
x = {00}
x = { }
x = { }
The value of variables comes from a CGI application, so, I have to know if there was passed some string, some number, some string with spaces or some string with zeroes. How can I test this thing? In each situation what is different than another one, the test is the same, but behavior is different...
Ion Filipski
