2009年3月15日星期日

Format in Perl

下面是一个format的例子
@,^表示替代域,^不同的是可以多行替代
...在域的后部,如果替代域过长则显示...
<,>,|表示左对齐,右对齐和居中显示
##.##表示数字
~~表示重复输出此行
@也占有一个控制位
$~:当前format名字
$^:当前top名字
$=:页面行数
$%:页号

#!/usr/bin/perl
use strict;
use warnings;

my $subject = "The revolution of POE server";
my $name = "woosley";
my $num = 1984.1023;
my $description = "This is a test of the format style in perl, but I
make it have a name The revolution of POE server. added to test";

open FO,">formate.txt";
format FH =
SUBJECT @<<<<<<<<<<<<<<<<<<<<<<<<<<<@####.##
$subject,$num
Assigned to: @<<<<<<<<<<<< ^<<<<<<<<<<<<<<
$name , $description
^<<<<<<<<<<<<<<~~
$description
.
#Below shows how to write an defined format into a opened filehandler
select(FO);
format TOP =
This is page @<<
$%
-------------------
.
select((
select(FO),
$~= 'FH',
$^ = 'TOP',
$= = 5,
)[0]);
write;


以上高亮代码用perltidy生成
perltidy -html -ss >mystyle.css
perltidy -html -pre test.pl
生成的html中会出现tab为8个空格长度而不能对齐的现象,不知道如何解决
发现perltidy不支持中文字符

没有评论: