如果您正在寻找程序中可用的东西,而不是命令提示符下的单行:
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
while (my $line = <DATA>) {
chomp $line;
my ($ip, $hostname, $color, undef, $mount) = split ' ', $line;
say "<tr><td>$ip</td><td>$hostname</td><td color=$color>$mount</td></tr>";
}
__DATA__
1.1.1.1 host red 70% /
1.1.1.1 host green 0% /dev/shm
1.1.1.1 host green 63% /staging/om_campaign_files
1.1.1.1 host red 71% /mnt/OBCDir
输出:
<tr><td>1.1.1.1</td><td>host</td><td color=red>/</td></tr>
<tr><td>1.1.1.1</td><td>host</td><td color=green>/dev/shm</td></tr>
<tr><td>1.1.1.1</td><td>host</td><td color=green>/staging/om_campaign_files</td></tr>
<tr><td>1.1.1.1</td><td>host</td><td color=red>/mnt/OBCDir</td></tr>