You are parsing FreeBSD port INDEX, right? AFAIK that is the right way to go.
On the other hand, you seem to use the first field to get the package
name, and that's the wrong way to go. IIRC you should use the second
field (/usr/ports/category/package), since that is the unique key.
e.g.
amarok-1.4.10_3|/usr/ports/audio/amarok
amarok-2.0.2_2|/usr/ports/audio/amarok-kde4
--
Seo Sanghyeon