[SP-pm] Dúvida sobre execução de comandos em Perl

Wallace Reis wallace at reis.org.br
Wed Jun 9 03:58:56 PDT 2010


On 08/06/2010, at 16:14, Andre Carneiro wrote:
> Tenho duas perguntas: 
> 
> 1 - Existe um comando chamado readpipe, que me retorna um array onde cada item do array corresponde a uma linha na saída do comando. Alguém sabe me dizer se é a mesma coisa e/ou é preferível usar readpipe do que um código igual a esse? ;


perldoc perlipc:
Using open() for IPC
"       You might notice that you could use backticks for much the same effect as opening a pipe for reading:

           print grep { !/^(tcp|udp)/ } `netstat -an 2>&1`;
           die "bad netstat" if $?;

       While this is true on the surface, it’s much more efficient to process the file one line or record at a time because then you don’t have to read
       the whole thing into memory at once.  It also gives you finer control of the whole process, letting you to kill off the child process early if
       you’d like."

--
   wallace reis/wreis  http://www.linkedin.com/in/wallacereis


More information about the SaoPaulo-pm mailing list