First things first: Perl is not shell scripting!
Second: you're using cat far too often. cut can read a file fine by itself, and wc, when given a file argument, won't even bother reading stdin.
Third: see perldoc perlform for Perl formatting instructions, which are ideal for report formatting.
---------- Post updated at 09:45 ---------- Previous update was at 09:29 ----------
(Almost) exactly your script, except without temporary files, pretty printing, and only 1 external call:
#!/usr/bin/perl
use strict;
use warnings;
my ( @dirlist, @dirlist1, @command );
my ( $dir, $dir1, $cmd );
format STDOUT_TOP=
+----------+---------------------+---------+
| Col 1 | Col 2 | Col 3 |
+----------+---------------------+---------+
.
format STDOUT=
| @<<<<<<< | @|||||||||||||||||| | @>>>>>>>|
$dir, $dir1, $cmd
.
format STDOUT_BOTTOM=
+----------+---------------------+---------+
.
open my $fh, '<', 'out.txt';
@dirlist = map { @_ = split /\|/; $_[0] } <$fh>;
close $fh;
@command = map { $_ - 2 } @dirlist;
@dirlist1 = split /\n/, qx/wc -l *e*/;
for ( my $i = 0 ; $i < scalar @dirlist1 ; $i++ ) {
$dir = $dirlist[$i];
$dir = '' unless defined $dir;
$dir1 = $dirlist1[$i];
$dir1 = '' unless defined $dir1;
$cmd = $command[$i];
$cmd = '' unless defined $cmd;
write;
}
$~ = 'STDOUT_BOTTOM';
write;
Will result in:
+----------+---------------------+---------+
| Col 1 | Col 2 | Col 3 |
+----------+---------------------+---------+
| 378462 | 3 test1.txt | 378460|
| 764 | 6 test2.txt | 762|
| 907834 | 1 test3.txt | 907832|
| | 10 total | |
+----------+---------------------+---------+
And you can adjust the formatting as you like, without having to change the whole code.