博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Perl语言入门-第五章-输入与输出-习题
阅读量:7079 次
发布时间:2019-06-28

本文共 1414 字,大约阅读时间需要 4 分钟。

1. 习题

   

2. 代码与输出

cat_reverse.pl

 1 
#
-----------------------------------------------------------#
 2 
# Source: Learning Perl, chapter5, exercise-1
 3 
# Date:   2012-01-15
 4 
# Author: xiaodongrush
 5 
#-----------------------------------------------------------#
 6 
use 
5.010;
 7 
while(<>) { 
chomp
unshift 
@array,
$_; }
 8 
foreach(
@array) { say 
$_; }
 9 <STDIN>
10 
#
 @_表示子程序的参数列表,$_是Perl的老地方,容易混淆

printf_example.pl

 1 
#
-----------------------------------------------------------#
 2 
# Source: Learning Perl, chapter5, exercise-2
 3 
# Date:   2012-01-15
 4 
# Author: xiaodongrush
 5 
#-----------------------------------------------------------#
 6 
use 
5.010;
 7 say 
"
Input several str! (Use Control+Z to Stop Input).
";
 8 
while(<>) { 
chomp
push 
@strs,
$_; }
 9 say 
"
1234567890
" x 
4;
10 
foreach(
@strs) { 
printf 
"
%20s\n
",
$_; }
11 <STDIN>

printf_example_2.pl

 1 
#
-----------------------------------------------------------#
 2 
# Source: Learning Perl, chapter5, exercise-3
 3 
# Date:   2012-01-15
 4 
# Author: xiaodongrush
 5 
#-----------------------------------------------------------#
 6 
use 
5.010;
 7 say 
"
Input several str! (Use Control+Z to Stop Input).
";
 8 
while(<>) { 
chomp
push 
@strs,
$_; }
 9 
print 
"
The Width of the Rule Line Width = 
"
$width = <STDIN>;
10 
print 
"
1234567890
" x (
$width/
10); 
11 
foreach(
1..
9) { 
if(
$_ <= (
$width%
10)) { 
print 
$_; } } say;
12 
foreach(
@strs) { 
printf 
"
%20s\n
",
$_; }
13 <STDIN>

3. 文件

   

转载地址:http://shpml.baihongyu.com/

你可能感兴趣的文章
mikadonic-文件访问控制设置(深层次的权限控制setfacl)
查看>>
这是标题,用来测试博客皮肤标题
查看>>
AJax详解
查看>>
从一段时间段中获取所有日期
查看>>
Java中如何设置表格处于不可编辑状态
查看>>
Java JTable视图窗口滚动并定位到某一行
查看>>
课堂练习
查看>>
HTML学习成果 制作一个空白简历
查看>>
使用mybatis自带工具,自动生成表对应domain、mapper.xml以及dao
查看>>
餐饮ERP相关问题FAQ
查看>>
基于 Vue.js 的移动端组件库mint-ui实现无限滚动加载更多
查看>>
Matrix Computations 1
查看>>
springboot上传代码到gitlab并发布上线操作
查看>>
FILE * fopen(const char * path,const char * mode);
查看>>
[Flask]sqlalchemy使用count()函数遇到的问题
查看>>
[python](Docker SDK)上传镜像到私有仓库(tls、身份认证)
查看>>
听说是阿里笔试题
查看>>
使用pm2管理nodejs应用
查看>>
MySQL基础之---mysqlimport工具和LOAD DATA命令导入文本文件
查看>>
php 读取文件头部两个字节 判断文件的实际类型
查看>>