That could be when $ENV{REMOTE_ADDRESS} isn't set. I just checked my
environment on four different machines here, and on none of them
REMOTE_ADDR is set.
>> :} @SubIP = split(/./, $Remote_IP_Address);
>>
>> /./ matches *any* character, except newlines. So, @SupIP will turn
>> into an array loaded with empty strings.
>>
>==================
>
> Actually, there is a period in there.... I found out that I also needed to
> put a \ in front of that period, then it works.

Ok, so now you learned a trick.

Do you also understand _why_ you need to put a backslash in front of
that dot? Abigail already mentioned that a dot matches *any* character
(except newlines). What you need to do is try to understand what was
said there. First you need to read the entry for split() in perlfunc
to realise that that is called a regular expression. And then you need
to read about regular expressions in perlre (and probably perlretut).
Use the perldoc command to read documentation.
>> :} if ($SubIP_1 =~ /$SubIP[0]\.$SubIP[1]\.\d+\.\d+/) {
>>
>> That regex will expand to: /\.\.\d+\.\d+/, and unlikely to match anything.
>>
>======================
>
> It seems to be working.... since I've included the \ in fron of the period
> in the split routine.

No. The regex that Abigail quoted was not working, since you complained
about it, with the original data. If you suddenly change the data then
the regex you posted would expand to something else than Abigail
quoted.

Be careful to read what people say, and respond appropriately.

Martien
--
|
Martien Verbruggen | Useful Statistic: 75% of the people make up
Trading Post Australia | 3/4 of the population.
|

[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]

In article <aIJbb.10555$>, says...
> I would like to do something like:
>
> if ($SubIP_1 =~ /$SubIP[0]\.$SubIP[1]\.\d+\.\d+/)
>
> But apparently, I can not use variables in the RegEx statement.
>
> Can someone explain this to me?
>
>
> Thanks,
>

You must be making some sort of error in your code because Perl does
allow using variables in a RegEx as in the following example.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!