perl fomatting数组打印出来

时间:2019-07-08 20:53:07

标签: perl formatting

这是数据这是IRC通道中的票证分配列表。

07:28:16 AM WJ INC1013210983
07:47.34 AM PP INC1013234284
08:48:54 AM AP INC1013212834
08:57:24 AM II INC1013212245
09:58:12 AM EB INC1013210008
10:28:22 AM JK INC1013210008
11:28:35 AM WJ INC1013212345
12:28:23 AM LC INC1013212290
01:19:15 AM WJ INC1013219946
02:03:16 AM JK INC1013213945
02:13:47 AM LC INC1013216958
03:32:52 AM WJ INC1013212290
03:52:01 AM BJ INC1013212280

此脚本将分配任务并剔除欧洲人,然后为美国机组人员设定顺序。

#!/usr/bin/perl

use strict;
use warnings;
my @team = ("AP","II","DS","WJ", "JK","LC","BJ") ;
my ( $team_regex ) = map {qr /$_/} join "|", map {quotemeta} @team;
my @orderdTeam ;
my @uni_orderdTeam ;
my @rev_orderdTeam ;

my $filename = shift @ARGV ;
open(my $fh, '<', $filename) or die "Could not open file $filename $!";
while (my $line = <$fh> ) {
    if ( $line =~ /^($team_regex)/ ) {
        push @orderdTeam, $1;
    }
}
close $fh;

print "AMER team members : @team\n";
print "Ordered: @orderdTeam\n";
@rev_orderdTeam = reverse @orderdTeam ;
print "Reverse: @rev_orderdTeam\n" ;

for my $uni (@rev_orderdTeam) {
    if ( ! grep( /$uni/, @uni_orderdTeam)) {
    push ( @uni_orderdTeam, $uni) ;
    }
}
print "Unique reversed : @uni_orderdTeam";

结果

$ ./spliton_colon_duplicate.pl delegate20190628
AMER team members : AP II DS WJ JK LC BJ
Ordered: WJ AP II JK WJ LC WJ JK LC WJ BJ
Reverse: BJ WJ LC JK WJ LC WJ JK II AP WJ
Unique reversed : BJ WJ LC JK II AP

我想得到这样的结果:

Formatting          Team members
------------------|---------------------------------
AMER team members : AP II DS WJ JK LC BJ
Ordered           : WJ AP II JK WJ LC WJ JK LC WJ BJ
Reverse           : BJ WJ LC JK WJ LC WJ JK II AP WJ
Unique reversed   : BJ WJ LC JK II AP

1 个答案:

答案 0 :(得分:0)

以下是使用Perl6::Form的示例:

use Perl6::Form;
# [...]
my @labels = ('AMER team members', 'Ordered', 'Reverse', 'Unique reversed');
print form
  ' Formatting         Team members         ',
  '------------------|----------------------',
  '{[[[[[[[[[[[[[[[} : {[[[[[[{*}[[[[[[[[[[[}', 
  \@labels, ["@team", "@orderdTeam", "@rev_orderdTeam", "@uni_orderdTeam"];

输出

 Formatting         Team members
------------------|----------------------
AMER team members : AP II DS WJ JK LC BJ
Ordered           : WJ AP II JK WJ LC WJ JK LC WJ BJ
Reverse           : BJ WJ LC JK WJ LC WJ JK II AP WJ
Unique reversed   : BJ WJ LC JK II AP