#!usr/bin/perl
use utf8; #引入utf8模块 脚本内的字符串使用utf8作为编码格式
binmode(STDOUT,":encoding(gbk)");
#标准输出使用gbk作为编码格式,也可以把gbk改为gb2312
binmode(STDIN,":encoding(gbk)");
#如果涉及到输入流,例如读文件,不加这条读中文文件会出现乱码
binmode(STDERR,":encoding(gbk)");
#如果异常错误中的字符串有中文,请加上STDERR,否则也会出现乱码 open( DATA, "> Error.txt" )
|| die "Unable to open error for write! - $!\n"; %IOLIST=('李白',{'age','18','height','185','weight','60kg'},
'李1',{'age','18','height','185','weight','60kg'},
'李2',{'age','19','height','180','weight','60kg'},
'李3',{'age','28','height','181','weight','60kg'},
'李4',{'age','21','height','182','weight','60kg'},
'李5',{'age','22','height','183','weight','60kg'},
'李6',{'age','23','height','184','weight','60kg'},
'李7',{'age','24','height','188','weight','60kg'},
'李8',{'age','25','height','187','weight','60kg'},
'李9',{'age','26','height','186','weight','60kg'},
'李10',{'age','27','height','189','weight','60kg'}
);
dumplist(\%IOLIST); sub dumplist
{
my $LIST = shift;
my $legend = 0;
foreach $item (sort keys %$LIST)
{
my @attributes = ();
my @legen = ();
print "$item:\n";
foreach $attr (sort keys %{$$LIST{$item}})
{
push(@legen, $attr);
push(@attributes, $LIST->{$item}{$attr})
}
print @legen , "\n" if $legend == 0;#打印数组,ageheightweight
$legend++, print DATA "item:", join(',', @legen), "\n\n" if $legend == 0;
print DATA "$item:\t", join(', ',@attributes),"\n\n";
}
}

输出结果:

D:\>Error.pl
李1:
ageheightweight
Wide character in print at D:\Error.pl line 47.
李10:
Wide character in print at D:\Error.pl line 47.
李2:
Wide character in print at D:\Error.pl line 47.
李3:
Wide character in print at D:\Error.pl line 47.
李4:
Wide character in print at D:\Error.pl line 47.
李5:
Wide character in print at D:\Error.pl line 47.
李6:
Wide character in print at D:\Error.pl line 47.
李7:
Wide character in print at D:\Error.pl line 47.
李8:
Wide character in print at D:\Error.pl line 47.
李9:
Wide character in print at D:\Error.pl line 47.
李白:
Wide character in print at D:\Error.pl line 47.

Error.txt

item:age,height,weight

李1:    18,    185,    60kg

李10:    27,    189,    60kg

李2:    19,    180,    60kg

李3:    28,    181,    60kg

李4:    21,    182,    60kg

李5:    22,    183,    60kg

李6:    23,    184,    60kg

李7:    24,    188,    60kg

李8:    25,    187,    60kg

李9:    26,    186,    60kg

李白:    18,    185,    60kg

perl使用print输入数据到文件的更多相关文章

  1. Python Linux 命令行执行脚本输出重定向print到日志文件

    reference: https://unix.stackexchange.com/questions/182537/write-python-stdout-to-file-immediately   ...

  2. Perl IO:随机读写文件

    随机读写 如果一个文件句柄是指向一个实体文件的,那么就可以对它进行随机数据的访问(包括随机读.写),随机访问表示可以读取文件中的任何一部分数据或者向文件中的任何一个位置处写入数据.实现这种随机读写的功 ...

  3. Perl文件名通配和文件查找

    在shell中使用*来对文件名进行通配扩展,在Perl中也同样支持文件名通配.而且perl中的glob通配方式和shell的通配方式完全一致,实际上perl的glob函数就是直接调用csh来通配的(如 ...

  4. perl 利用管道读取压缩文件内容

    perl的文件句柄不仅支持普通文件, 还支持管道,今天需要统计一个fastq文件中的序列数和碱基数,而NGS的fastq文件一般都是gzip压缩的,所以 需要读取压缩文件中的内容,代码如下: my ( ...

  5. python下print结果到文件中的方法

    目的是将print的结果输出到一个文件中,比如这个文件在D:\lianxi\out.txt下,我用的windows: s = '1234' f = open (r'D:\lianxi\out.txt' ...

  6. Perl根据日期分割数据文件

    Perl的优势:比C好写,比Shell高效,Linux普遍支持. #!/usr/bin/perl -w # auth: lichmama@cnblogs.com # what: split data_ ...

  7. perl语言中的.pm文件和.pl文件区别

    perl...呵呵呵 按照惯例,.pm 应该保存 Perl Module,也就是 Perl 模块.例如 Socket.pm.pl 应该保存 Perl Library,也就是 Perl 库文件.例如 p ...

  8. print 输出到文件

    content = """We have seen thee, queen of cheese, Lying quietly at your ease, Gently f ...

  9. perl 读取json 格式的文件

    使用JSON 模块中的 decode_json 函数,将json文件中的数据解码为perl 中的对象,然后进行处理 代码如下: #!/usr/bin/env perl use JSON; use En ...

随机推荐

  1. idea中设置注释颜色

    1. 打开idea,右上角File-->Settings 2.找到Language Defaults-->Comments里面Block comment和Line comment 3.Bl ...

  2. Centos7中用Docker安装MySQL教程

    第一步 安装Docker 1.1 参考这位博主给出的命令安装好 https://blog.csdn.net/weixin_43423864/article/details/109481260 第二步 ...

  3. Linux有趣命令

    通外网 下载使用阿里云镜像源:wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.re ...

  4. Homework4

    书籍链接:https://www.ituring.com.cn/article/13466(why Software Development Methodologies Suck?) 问:读 why ...

  5. c#中容易被忽视的foreach

    有句俗语:百姓日用而不知.我们c#程序员很喜欢,也非常习惯地用foreach.今天呢,我就带大家一起探索foreach,走,开始我们的旅程. 一.for语句用的好好的,为什么要提供一个foreach? ...

  6. RedHat Linux升级内核

    操作系统:Red Hat 6.4 内核文件:linux-3.10.1.tar.gz  https://www.cnblogs.com/cherish-sweet/p/newyum.html uname ...

  7. Minio服务限制/租户

    官方文档地址:http://docs.minio.org.cn/docs/master/minio-server-limits-per-tenant 纠删码 (多块硬盘 / 服务) 浏览器访问 Lim ...

  8. Mapping

    dynamic针对的是新增的字段,不是对mapping中已有的字段 (原有mapping中的字段不受影响,只影响新增的字段) 当dynamic被设置成false的时候,存在新增字段可以被写入到索引文件 ...

  9. 【前端必会】webpack loader 到底是什么

    概述 webpack的使用中我们会遇到各种各样的插件.loader. webpack的功力主要体现在能理解各个插件.loader的数量上.理解的越多功力越深 loader是什么呢? 背景 了解load ...

  10. 了解Pytorch|Get Started with PyTorch

    一个开源的机器学习框架,加速了从研究原型到生产部署的路径. !pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple import ...