Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple comparison question 2

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Super easy question for you guys.

I'm looking for a 'one-liner' that will achieve the following:
- Check if param{'name'} equals "bozo" only is param{'name'} is not null (is defined).

Code:
if ($param{'name'} ne '' && $param{'name'} eq 'bozo') {
	print "foo";
}
 
Looks good to me.
You can probably change
$param{'name'} ne ''
to just
if ($param{'name'} && $param{'name'} eq 'bozo')

as I dont' think it gets defined unless it's got data passed to it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 

After reading my question, I realized my question wasn't clear.
What I want is:

If param{'name'} is not NULL, check if equals to "bozo"; then print "foo". If value is NULL, print "foo"

I want to basically avoid doing this:

Code:
if ($param{'name'} && $param{'name'} eq 'bozo') {
# Filter; push records with name = 'bozo'
push (@Found, $Record);

}
else {
# No Filter; push all records
push (@Found, $Record);
}
 
Code:
if (($param{'name'} && $param{'name'} eq 'bozo') || ! $param{'name'}){
	print "foo\n";
}



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
if (param{'name'} eq 'bozo') would only be true if the param exists, and is equal to 'bozo'

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
duh :)

Code:
if ($param{'name'} eq 'bozo' || ! $param{'name'}){
	print "foo\n";
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top