does this code look right
No. In fact, I can't even tell what you're trying to do.
Start by adding use strict; use warnings;
In reply to Re: sanity check by ikegami in thread sanity check by marutcar