使用 Perl 进行格式化输出的最佳方式 [英] Best way to have a formatted output with Perl

查看:15
本文介绍了使用 Perl 进行格式化输出的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将字符串输出为八列,但我想保持间距不变.我不想用 HTML 来做,但我不知道如何正常做.示例:

I want to output strings into eight columns, but I want to keep the spacing the same. I don't want to do it in HTML, but I am not sure how to do it normally. Example:

Something    Something     Something     Something     Something
Else         Else          Else          Else          Else
Another      Another       Another       Another       Another

行数每天都在变化,但列数始终保持不变.最好的方法是什么?

The amount of rows will change daily, but the column number will always stay the same. What is the best way to do this?

推荐答案

printf

    printf "%-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s
",
            $column1, $column2, ..., $column8;

将模板中的11"更改为您需要的任何值.

Change "11" in the template to whatever value you need.

这篇关于使用 Perl 进行格式化输出的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆