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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if variable contains certain data

Status
Not open for further replies.

roywills

Technical User
Feb 18, 2008
6
US
I am trying to determine if a varaible is defined and if it also certain data. I am using the defined function to test if it is set, but am having trouble finding a way to test if it contains a certain word anywhere in te variable.

Can anyone offer any insight on this?
 
if ($var =~/whatever/) {

Do blah
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[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;
 
Note that /whatever/ doesn't have to be a literal, it can be a pattern, too. But entire books have been written on regular expressions... [smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
roywils,

lets see what you have tried so far.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top