It would be better to use a boolean for `$pd`, so `$pd = false` here, and then `$pd = true` in the loop.