in reply to Is there an InString-like function?
or in some languages if the first character of the string $var is 1,2,3,4 or 5Well, in perl we 'only' have the scalar type, but you can use it as a string. Then a regex might be your solution, TIMTOWTDI. For your example you'd write:
and you can do a lot of further nice things with regexes, have a look at our Tutorials.print '$var starts with 1, 2, 3, 4 or 5' if ($var =~ /^[12345]/); print '$var contains 1, 2, 3, 4 and/or 5' if ($var =~ /[12345]/); print '$var starts with 1, 2, 3, 4 or 5' if ($var =~ /^[12345]/);
As a remark, this method only works for simple cases, if you want something like $var in (12, 25, 100..233) then a regex is not ideal. Consider the other solutions presented so far for these cases.
-- Hofmator
|
|---|