in reply to Re: qx + sed not working
in thread qx + sed not working

Oh my, you're right. It is the blank lines that is causing the loop to stuck up.

Files.txt contains the ff. lines: C:/ProcessFiles/File1.txt C:/ProcessFiles/File2.txt C:/ProcessFiles/File3.txt C:/ProcessFiles/File4.txt C:/ProcessFiles/File5.txt
#!/usr/bin/perl use strict; use warnings; use File::Find; use Cwd; my @SetBCs; open(my $file, "<", "Files.txt") or die "Failed to open file: $!\n"; while(<$file>) { chomp; push @SetBCs, $_; } close $file; foreach (@SetBCs) { my $command = qx(sed -n "/Sets/,/Rules/p" $_); print $command; }

Thanks!

Replies are listed 'Best First'.
Re^3: qx + sed not working
by hippo (Archbishop) on Apr 20, 2018 at 13:58 UTC

    Without shelling out:

    #!/usr/bin/env perl use strict; use warnings; use Path::Tiny; chomp (my @SetBCs = <DATA>); for my $fname (@SetBCs) { next unless $fname; my @command = grep {/Sets/ .. /Rules/} path ($fname)->lines; print @command; } __DATA__ C:/ProcessFiles/File1.txt C:/ProcessFiles/File2.txt C:/ProcessFiles/File3.txt C:/ProcessFiles/File4.txt C:/ProcessFiles/File5.txt

    That's just one way. You can put your loading of @SetBCs back to reading from the file, but the rest of it should work fine as-is.