[EMAIL PROTECTED] wrote:
>
> [EMAIL PROTECTED] writes:
>>
>> [EMAIL PROTECTED] wrote:
>>>
>>> Hi,
>>>
>>> I am a beginner in perl and am having a dickens of a time trying to
>>>
>>> identify this pattern in messages. [URL
>>>
>>> Here is what I have:
>>>
>>> if ($FORM{'message} =~ /\[URL/ig) {
>>> #do something;
>>> }
>>>
>>> Where $FORM('message') is a messaage that includes many lines and
>>> [url=http://www.mywebspace.com[/url]. But this doesn't result in true
>>>
>>> even though I know the message contains the string [url. Can anyone tell
>>> me what could be the
>>>
>>> problem? Or perhaps a better way to identify a messages with the [url
>>> anywhere in it. Thanks for any help.
>>
>> works for me!
>> I assume missing ' is just a typo else you would get compile error
>>
> [EMAIL PROTECTED] re]$ cat url.pl
> #! /usr/bin/perl
>
> use strict;
> use warnings;
>
> my %FORM;
>
> $FORM{'message'} = "
> Where \$FORM('message') is a messaage that includes many lines and
> [url=http://www.mywebspace.com[/url]. But this doesn't result in true
> even though I
> know the message contains the string [url. Can anyone tell me what
> could be the
> problem? Or perhaps a better way to identify a messages with the [url
> anywhere in it. Thanks for any help.";
>
> This works as long as the escaped bracket is not included. As soon as I
> include the \[ it no longer works? No longer returns true. There has to be
> an answer to this? I don't get it? Could it be attempting to match the \ as
> well?
Jim, please show us something that doesn't work for you. Splicing the code from
your two posts together and fixing the typp that John pointed out, I get:
use strict;
use warnings;
my %FORM;
$FORM{'message'} = "
Where \$FORM('message') is a messaage that includes many lines and
[url=http://www.mywebspace.com[/url]. But this doesn't result in true
even though I
know the message contains the string [url. Can anyone tell me what
could be the
problem? Or perhaps a better way to identify a messages with the [url
anywhere in it. Thanks for any help.";
if ($FORM{'message'} =~ /\[URL/ig) {
print "something\n";
}
which dutifully prints "something".
It's worth pointing out that the /g is unnecessary and wrong, and the single
quotes around the hash key 'message' are just unnecessary, but they don't stop
your code working!
Let us know...
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>