我正在尝试从 Perl 写入文件。我只想以制表符分隔的格式写入数据。但是,我正在编写的数据长度不同,并且没有对齐。
例如,我正在尝试编写如下内容:
Name Education Fav_Car MoneyInBank
josh High School Porche 500
SomeOtherName PHD Hyundai 50000
我只希望数据与顶部的标题对齐。
我正在输出这样的数据:
printf FILE ("%s%20s%20s\n", "Name", "Ed", "Car");
while (($name, $ed, $car) = $sth->fetchrow_array) {
printf FILE ("%s>>>>>>>>>>>>>%40s%40s\n", $name, $ed, $car);
};