#!/usr/local/bin/perl

use IPC::Open3;  # para redireccionar stdin, stdout stderr dum comando

$pid=open3(Writer, Reader, Error, "prolog -l t5.prolog") 
      || die "cant prolog" ;

while(<>) {        # o gato mia  -> [o,gato,mia].
  chop;
  print Writer "[".join(",",(split))."].\n";
}

print Writer "end.\n";
close Writer || die "close error";        # guarantees flushing


while(<Reader>){   # [o,gato,mia] -> o gato mia 
 chop;
 s/[\[\]]//g;
 print join(" ",split(",",$_)) . "\n" ;
}
