in reply to getting 0 to print

In this statement:
print join ( '|', map ( $_ || '0', trim( @r )) );
You can't really use || 0 as the 0 will result in false. something like this should work though:
print join ( '|', map ( $_ ? $_ : '0', trim( @r )) );
Note this is untested code. but what this does is check for the "trueness" of $_ and if it is true return it otherwise return 0

-enlil