I am trying to create a simple program that does these five things
I have labeled the cases on the code I am providing. Every time I run this, I do not get errors, but the same response in return. I am trying this to improve my file scanning skills. If anyone has any knowledge on this topic I would be more than grateful.提前致谢。
#!/usr/bin/perl
use strict;
use warnings;
print ("Enter a file name: ");
my $infile = <STDIN>; #Prompts the user for input
chomp ($infile); #Chomps the $infile Variable.
#****CASE ONE****
if (-e $infile) {
print ("File '$infile' does not exist.\n");
exit;
}
#****CASE TWO****
elsif (-f $infile) {
print ("Not a regular file or directory.\n");
exit;
}
#****CASE THREE****
open ( my $input, '<', $infile ) or die $!;
print ("Can not open input file '$infile': Permission denied. ");
#****CASE FOUR****
#for (my $inf = 1; ; ++$_)
my $inf = 9**9**9;
if (-e $infile =~ /^[a-zA-Z]+$/) {
} else {
print ("File '$infile' containts invalid data.\n");
exit;
}
#****Case Five****
my $Int_Pos = 0;
my $Int_Neg = 0;
my $Int_Dec = 0;
open(FHIN, '<', $infile); #Opens the file prompted by user.
my @lines = <FHIN>; #Variable storing the number of lines in the file.
chomp( @lines );
close(FHIN); #File handle is closed.
while (my $line = <$input> ) { #iterates the file line by line, making $_ as teh defaule variable.
$Int_Pos++ if $line >= 0;
$Int_Neg++ if $line >= 0;
$Int_Dec++ if $line >= 0;
my $sum = $Int_Pos + $Int_Neg + $Int_Dec;
my $Observations = @lines;
my $Mean = $sum/3;
print ("Sum: '$sum'\n");
print ("Observations: '$Observations'\n");
print ("Mean: '$Mean'\n");
}
okay, so there are multiple things wrong:
if (-e $infile) 应该
`if (not -e $infile) `
elsif (-f $infile) has the same issue of testing the opposite of what you want elsif (not -f $infile)
also, this print will happen when the file DOES open:`
open ( my $input, '<', $infile ) or die $!;
print ("Can not open input file '$infile': Permission denied. ");`
instead change it to:
`open ( my $input, '<', $infile ) or die("Can not open input file '$infile': $!");`
this line is nonsensical if (-e $infile =~ /^[a-zA-Z]+$/) im guessing in case 4 you will want something along the lines of
foreach $line (<$infile >){
$matches = () = $line =~ /^(\d+)$/;
if($matches != 1){
die "line does not contain a single number";
}
$sum += $1;
}
this is a hasty, approximate code that doesn't use strict (you should use strict!) which should help you figure out the rest
1) 目前测试过能用的 USB 以太网卡如下所示,其中 RTL8153 USB 千兆网卡插入开 发板的 USB 2.0 Host 接口中测试可以正常使用,但是速率是达不到千兆的,这点请 注意 2) 首先将 USB 网卡插入开发板的 USB 接口中,然后在 USB 网卡中插入网线,确 保网线能正常上网,如果通过 dmesg 命令可以看到下面的 log 信息,说明 USB 网卡...
很多朋友多次问到什么是网关、dns、子网掩码,三层交换机,它们定位的用途;确实,因为网络技术在弱电中确实应用非常广泛,我们平时在 vip 技术群中也是不断的讨论到网关、vlan、三层交换机或子网掩码等问题,今天我们就一起用通俗方式一次性了解清楚。 一、什么是 vlan? VLAN 中文是 “虚拟局域网”。LAN 可以是由少数几台家用计算机构成的网络,也可以是数以百计的计算机...
(乐播科技的三位创始人,从右往左依次为:冯森、廖峰、陈锡华) 电视在家居生活中扮演的角色重新获得了人们的认知,这块屏幕成为巨头们谋划的方向,其中一个属性便是家庭的娱乐中心。但在国内,各种基于Android平台的电视和盒子又面临游戏内容缺乏的窘境。当然,很多人或者团队都在努力着希望完善这个生态系统,但是好像没有那么简单。 另一方面,苹果系统已经是非常成熟的平台,各类iOS游戏的质量也很高。于是,来自...
该案例是OSS Java SDK的示例程序,您可以修改endpoint、accessKeyId、accessKeySecret、bucketName后直接运行。 本示例中的并不包括OSS Java SDK的所有功能,详细功能及使用方法,请参看“SDK手册 > Java-SDK”, 链接地址是:https://help.aliyun.com/document_detai...
事情是这样的, 最近需要开发Orcale的数据库. 于是使用了EF 加上 Oracle.ManagedDataAccess.Client 这个Oracle.ManagedDataAccess 很好用, 不需要orcale 客户端就能用. 但是这个类库有个地方不是非常好用. 数据读取出了问题,它的提示非常非常让人气愤. 啥调试信息都没有..只有一个提示 “类型转换异常”. 大...
了解Spring框架 好处 : 1.不依赖于应用服务器. 2.IOC(控制反转)技术实现组件控制. 通过DI(依赖注入)技术提高了组件之间的解耦. 3.通过AOP(面向切面编程)技术实现安全、事务、日志功能的统一管理, 提高复用. 4.Spring框架可以几乎与其他任何框架进行良好的整合使用. 5.Spring所有项目之间不相互依赖. IOC : 控制反转. 本质: 将手动创建对象的工作,交给Sp...
物理层 **、维持、关闭通信端点之间的机械特性、电气特性、功能特性以及过程特性。该层为上层协议提供了一个传输数据的可靠的物理媒体。简单的说,物理层确保原始的数据可在各种物理媒体上传输。物理层记住两个重要的设备名称,中继器和集线器。 中继器: 又称转发器,原理是信号再生和还原,扩大网络传输距离。 仅作用于信号的电气部份,不管数据中是否有错误数据或不适合网段的数据。 中继器的两端既能连接相同的媒体又能...
修改注册表 Windows Explorer Shell支持Overlay Icon最多15个,Windows自身已经使用了4个,所以就只剩下了11个供我们使用。如果你之前安装了例如Groove这样的软件,那么可能我们可利用的就更少了,轮不到Tortoise了。像这样的情况,我们可以调整Tortoise图标名称的字母顺序,来提高Tortoise的优先位,因为Windows内部就是安装名称的字母顺序...
DataX系列 [第一章 DataX篇—阿里开源ETL同步工具](https://blog.csdn.net/qq_33451695/article/details/115048824?spm=1001.2014.3001.5501). 离线同步作业分析及JSON构建 DataX系列 前言 一、思路 二、增量同步问题 触发器 双向同步循环问题 二、插件扩展 前言 因业务需要,存在数据源...
Last years Chicago was full of gangster fights and strange murders. The chief of the police got really tired of all these crimes, and decided to arrest the mafia leaders. Unfortunately, the structure ...
I am examining the interaction between a continuous variable (bloodq) and a categorical variable with three levels (ER, RB, and WB). In order to see how the betas differ across tissue types, I would l...
I want to pass the output of ConvLSTM and Conv2D to a Dense Layer in Keras, what is the difference between using global average pooling and flatten Both is working in my case. That both seem to work d...
I am writing a validation groovy script for a test step, intended to test a SOAP Web Service. Now, I want to call the same test step, with different input value from the groovy script. Is it possible?...
I have a problem with my web application with wicket. I am using wicket 6.14. I can't say exactly what the problem is, but I can describe the problem. I am using a self written pagestore, which uses h...
In unity is it possible to load a resource that is out side of the resources folder. I want the user to be able to set a textAsset variable from a file outside of the Assets directory entirely. You ca...