在我的代码中,我想以表格形式查看CSV中的所有数据,但它只显示最后一行.第1行和第2行怎么样?这是数据:
1,HF6,08-Oct-08,34:22:13,df,jhj,fh,fh,ffgh,gh,g,rt,ffgsaf,asdf,dd,yoawa,DWP,tester,Pattern 2,hf35,08-Oct-08,34:12:13,dg,jh,fh,fgh,fgh,gh,gfh,re,fsaf,asdf,dd,yokogawa,DWP,DWP,Pattern 3,hf35,08-Oct-08,31:22:03,dg,jh,fh,fgh,gh,gh,gh,rte,ffgsaf,asdf,dfffd,yokogawa,DWP,DWP,ghh
这是代码:
#! /usr/bin/perl print "Content-type:text/html\r\n\r\n"; use CGI qw(:standard); use strict; use warnings; my $line; my $file; my ($f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$f10,$f11,$f12,$f13,$f14,$f15,$f16,$f17,$f18,$f19); $file='MyFile.txt'; open(F,$file)||die("Could not open $file"); while ($line=) { ($f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$f10,$f11,$f12,$f13,$f14,$f15,$f16,$f17,$f18,$f19)= split ',',$line; } close(F); print ""; print ""; print ""; print " FUSION SHIFT REPORT "; print ""; print ""; print "
"; print ""; print "";"; print " "; print "RECORD No. "; print "TESTER No. "; print "DATE "; print "TIME "; print "DEVICE NAME "; print "TEST PROGRAM "; print "DEVICE FAMILY "; print "SMSLOT "; print "DIE LOT "; print "LOADBOARD "; print "TESTER "; print "SERIAL NUMBER "; print "TESTER CONFIG "; print "SMSLOT "; print "PACKAGE "; print "SOCKET "; print "ROOT CAUSE 1 "; print "ROOT CAUSE 2 "; print "ROOT CAUSE 3 "; print ""; print " "; print "$f1 "; print "$f2 "; print "$f3 "; print "$f4 "; print "$f5 "; print "$f6 "; print "$f7 "; print "$f8 "; print "$f9 "; print "$f10 "; print "$f11 "; print "$f12 "; print "$f13 "; print "$f14 "; print "$f15 "; print "$f16 "; print "$f17 "; print "$f18 "; print "$f19 "; print "
Paul Dixon.. 14
您需要在里面输出表行在while循环,因为这是您读取行的位置.
所以改变代码吧
输出表头
逐行读取文件输出表行
输出表格页脚
如果稍微简化一下,这就是你的循环看起来如何......
while ($line=) { print " "; my @cells= split ',',$line; foreach my $cell (@cells) { print " "; }$cell "; } print "
小智.. 7
HTML :: Template会让您的生活更轻松.这是我的缩减模板.
#!/usr/local/bin/perl use strict; use warnings; use HTML::Template; my @table; while (my $line = ){ chomp $line; my @row = map{{cell => $_}} split(/,/, $line); push @table, {row => \@row}; } my $tmpl = HTML::Template->new(scalarref => \get_tmpl()); $tmpl->param(table => \@table); print $tmpl->output; sub get_tmpl{ return <TMPL } __DATA__ 1,HF6,08-Oct-08,34:22:13,df,jhj,fh,fh,ffgh,gh,g,rt,ffgsaf,asdf,dd,yoawa,DWP,tester,Pattern 2,hf35,08-Oct-08,34:12:13,dg,jh,fh,fgh,fgh,gh,gfh,re,fsaf,asdf,dd,yokogawa,DWP,DWP,Pattern 3,hf35,08-Oct-08,31:22:03,dg,jh,fh,fgh,gh,gh,gh,rte,ffgsaf,asdf,dfffd,yokogawa,DWP,DWP,ghh
AmbroseChape.. 6
$f1,$f2,$f3,$f4任何时候你都会看到类似闹钟的代码应该消失.使用数组.
1> Paul Dixon..:您需要在里面输出表行在while循环,因为这是您读取行的位置.
所以改变代码吧
输出表头
逐行读取文件输出表行
输出表格页脚
如果稍微简化一下,这就是你的循环看起来如何......
while ($line=) { print " "; my @cells= split ',',$line; foreach my $cell (@cells) { print " "; }$cell "; } print "
2> 小智..:HTML :: Template会让您的生活更轻松.这是我的缩减模板.
#!/usr/local/bin/perl use strict; use warnings; use HTML::Template; my @table; while (my $line = ){ chomp $line; my @row = map{{cell => $_}} split(/,/, $line); push @table, {row => \@row}; } my $tmpl = HTML::Template->new(scalarref => \get_tmpl()); $tmpl->param(table => \@table); print $tmpl->output; sub get_tmpl{ return <TMPL } __DATA__ 1,HF6,08-Oct-08,34:22:13,df,jhj,fh,fh,ffgh,gh,g,rt,ffgsaf,asdf,dd,yoawa,DWP,tester,Pattern 2,hf35,08-Oct-08,34:12:13,dg,jh,fh,fgh,fgh,gh,gfh,re,fsaf,asdf,dd,yokogawa,DWP,DWP,Pattern 3,hf35,08-Oct-08,31:22:03,dg,jh,fh,fgh,gh,gh,gh,rte,ffgsaf,asdf,dfffd,yokogawa,DWP,DWP,ghh
3> AmbroseChape..:$f1,$f2,$f3,$f4任何时候你都会看到类似闹钟的代码应该消失.使用数组.
这应该是一个评论.它并不试图回答这个问题.
4> Greg Hewgill..:请允许我用一个较小的例子来演示.
my $f; while ($line =) { $f = $line; } print $f; 上面的代码将读取文件F的每一行,将每一行分配给变量
$f
.每次分配新行时,前一行都会被覆盖.当它到达文件末尾时,它会打印出$f
一次的值.my $f; while ($line =) { $f = $line; print $f; } 上面的代码
推荐阅读
如何解决《C3中的换行符通过JavaScript生成SVG图表》经验,为你挑选了1个好方法。 ... [详细] 如何解决《Laravel5.1使用限制在()方法中的雄辩》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何将Pandas列多索引名称作为列表》经验,为你挑选了1个好方法。 ... [详细] 如何解决《ReduxReact从API创建初始状态》经验,为你挑选了1个好方法。 ... [详细] 如何解决《Laravel雄辩的模型如何从关系表中获取数据》经验,为你挑选了1个好方法。 ... [详细] 如何解决《并行检查md5文件》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何按计划扩展或缩小AzureAppService实例大小?》经验,为你挑选了0个好方法。 ... [详细] 如何解决《Magento2:将产品属性添加为媒体图像》经验,为你挑选了1个好方法。 ... [详细] 如何解决《将Node.js内存使用限制为每个进程少于300MB》经验,为你挑选了1个好方法。 ... [详细] 如何解决《ReactNativeChildParent通信》经验,为你挑选了1个好方法。 ... [详细] 如何解决《c编译器警告:在参数列表中声明'structx'》经验,为你挑选了1个好方法。 ... [详细] 如何解决《Python:忽略xml.etree.ElementTree中的命名空间?》经验,为你挑选了0个好方法。 ... [详细] 如何解决《iOS:NSCalendarUnitWeekday的值是星期一的1》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何从Laravel中的路由传递Request对象?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《警告:出于安全原因已禁用ini_set()》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何指定War文件中资源的路径?》经验,为你挑选了0个好方法。 ... [详细] 如何解决《使用C将十六进制值存储到数组后打印十六进制值》经验,为你挑选了1个好方法。 ... [详细] 如何解决《'${var///+}'在shell脚本中的含义是什么?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《VS2015在DebuggerStepTrough中抛出异常?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《在h2o中加载大于内存大小的数据》经验,为你挑选了1个好方法。 ... [详细]吐了个 "CAO" !Tags | 热门标签RankList | 热门文章
- 1获取下一个小时的时间戳
- 2用凌空上传多个图像?
- 3屏幕上的C#WinForms程序中的闪烁清除
- 4如何git责备一个目录
- 5在Dex阶段构建大型Codename One应用程序时出错
- 6PowerShell-Set-Culture似乎没有任何改变
- 7MVC 5绕过Windows身份验证用户身份验证的用户
- 8Opcache清除太快
- 9java,l = inputStream.readLine())!= null背后的原理逻辑
- 10如何在Swift中删除AVPlayerViewController上的双击缩放功能
- 11二进制运算符'&'不能应用于'SCNetworkReachabilityFlags'和'Int'类型的操作数
- 12线性时间Euler的Totient函数计算
- 13安装Rcompression软件包时出错
- 14渲染问题无法加载LayoutLib:
- 15公共与受保护的抽象类方法
- 16为什么没有调用构造函数?
- 17如何在IOS键盘顶部的键盘上添加完成按钮?
- 18在两秒钟之后做一些事情
- 19如何在python中找到facebook上的朋友的名字
- 20对于创建表查询,query.executeUpdate()在hibernate中返回什么
DevBox开发工具箱 | 专业的在线开发工具网站 京公网安备 11010802040832号 | 京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有