4 ms·
I'm not sure why you'd want a count that includes your delimiter lines nor why you'd want to run the binaries twice for that matter. Real programming languages,
by cestith 9y ago
I'm not sure why you'd want a count that includes your delimiter lines nor why you'd want to run the binaries twice for that matter. Real programming languages, including Bash, have variables.
There are a number of ways to do these same things. Some of them mirror your code more closely than others. Here's my first shot using a core module, since someone already did one with no modules that works much like your code.
use IPC::Run3;
my @lines;
sub f {
my @command = qw( ls / );
run3 \@command, \undef, \@lines;
}
f();
open my $out, '>','out.txt' or warn "can't write to out.txt : $!\n";
printf $out "--\n%s--\n", (join '', @lines);
print scalar @lines . "\n";
Now I'd make that a bit cleaner and more reusable of course. I'd probably take the commands to run from the command line or a configuration file. I'd probably return an array or use a reference to one rather than making a file-level lexical array and just using that from a subroutine.