My experience is, that the functions $put/$puts cannot be used as an argument within an expression.
I use the function $put/$puts always at the top most level.
For example (this is a different algorithm than yours, just to show the principle) ...
$put(myvar,'a')
$puts(myvar,$if($eql(1,2),'bcdef','1 <> 2'))
$get(myvar)
See also ...
/t/3727/1
Check if field value is identical for all selected tracks
DD.20121104.1800.CET