Re: subroutine call makes foreach exit?



On 11/16/06, Andy Greenwood <greenwood.andy@xxxxxxxxx> wrote:

if (/^$domain.+MX\s+(\d+)\s+(.+)/) {

Because $domain is a string (and not a pattern), interpolating it into
a pattern could cause troubles. First, any metacharacters it contains
may affect the match. But also, is that pattern going to mistakenly
find the site "example.com" when the string is actually
"example.com.jp"? These patterns probably need to be crafted a little
more carefully. (If you know your data to be well behaved, this may
not be an issue.)

If I do make the call to getAforMX(), it gets the A records for the
first server, then mysteriously exits the foreach loop which surrounds
the call to getAforMX().

It's not so mysterious when you see what the foreach loop and the
subroutine have in common: @digOut. The sub modified the array while
foreach was still stepping through it. In fact, it's probably a bad
idea for that sub to modify any variables from the surrounding scope;
if that is truly necessary, it should at least be commented.

Cheers!

--Tom Phoenix
Stonehenge Perl Training
.



Relevant Pages

  • Re: Last row in foreach loop
    ... foreach loop other then setting up a loop counter that you manually increment? ... this pattern will be made even simpler with' ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: possible DIR["**"] anomaly
    ... Is my documentation wrong or what am I doing wrong? ... Note that this pattern is not a regexp (it's closer to a shell ... glob) and may contain the following metacharacters: ...
    (comp.lang.ruby)
  • Re: possible DIR["**"] anomaly
    ... Is my documentation wrong or what am I doing wrong? ... Note that this pattern is not a regexp (it's closer to a shell ... glob) and may contain the following metacharacters: ...
    (comp.lang.ruby)
  • possible DIR["**"] anomaly
    ... Is my documentation wrong or what am I doing wrong? ... Returns anArray of filenames found by expanding the pattern given in aString. ... Note that this pattern is not a regexp (it's closer to a shell glob) and may contain the following metacharacters: ...
    (comp.lang.ruby)