I'm sorry I wasn't very explicit. Basically, these statements
occur as part of an if statement and I am trying to determine
if the strings "/home", "/mail", or "cat: cannot open /home/$username/$file"
occur in the variable $columns[0]. If, for example,
"/home" does occur in the variable as part of a string,
I want to display the contents of the
variable. If it does not occur, I want to display an error
to the user. My problem is with the regular expression.
In psudo-code, my statement would be something like:
if (the string within $columns[0] contains the substring "/home")
{
take an action
}
I know that PHP can search for substrings with a function, but
I am not sure how to do this in perl and am wondering if
there is a function to do this or if I must use regular expressions.
Thanks for your input; I'll try to make my posts a bit more explicit.
updated 2003-06-24 by mirod: replaced [ and ] by [ and ] respectively. | [reply] [d/l] |
if ($columns[0] =~ /"\/home"/)
{
take an action;
}
and so forth. This assumes you really want the quotes in the string; if you don't, just remove them from the regex. | [reply] [d/l] |
This syntax worked well. It is exactly what I am looking for.
Thank you very much.
| [reply] |
If I understand your question , you might be able to use alteration as in if ($var=~/home|mail|cat: cannot open/){do whatever}
You might not need to match the entire last string as long as the part you match is unique. I'd try to stay away from the $username stuff since it can change
Time flies like an arrow, fruit flies like banannas
| [reply] [d/l] |