Wednesday, April 13, 2011

Capturing the output of a shell command

Just being picky, this will print all of the output lines on a single
line separated by spaces. Since you probably want to see them on
separate lines, you could either not chomp

   my @files = qx(ls);
   print @files;

or append newlines on output

   chomp(my @files = qx(ls));
   print "$_\n" foreach @files;

No comments: