我的文件名是“rootpass”,我试图像这样阅读,
Unsuccessful stat on filename containing newline at ReadFile.pl line 106.
我收到这样的错误,
my $passfile = "$jobDir\/rootpass";
106是if()行。我试过以下,
my $passfile = "$jobDir//rootpass";
逃避逃脱的问题rootpass
逃避'r'所以它不会认为我在文件名中有一个返回字符如何在变量$jobDir
中包含的目录名下读取名称为using UnityEngine;
using System.Collections;
public class ChangeImage : MonoBehaviour {
public Texture[] frames;
public int CurrentFrame;
void OnMouseDown() {
if (GlobalVar.PlayClip == false){
GlobalVar.PlayClip = true;
} else {
GlobalVar.PlayClip = false;
}
}
public void Start() {
frames = Resources.LoadAll<Texture>("");
}
// Update is called once per frame
void Update () {
if(GlobalVar.PlayClip == true){
CurrentFrame %= frames.Length;
CurrentFrame++;
Debug.Log ("Current Frame is " + CurrentFrame);
GetComponent<Renderer>().material.mainTexture = frames[CurrentFrame];
}
}
}
的文件?
答案 0 :(得分:0)
对原始问题有很多好评,但你也是:
这是您脚本的现代perl版本:
use 5.012; # enables "use strict;" and modern features like "say"
use warnings;
use autodie; # dies on I/O errors, with a useful error message
my $jobDir = '/path/to/job/directory';
my $passfile = "$jobDir/rootpass";
say "filename: '$passfile'";
# No need for explicit error handling, "use autodie" takes care of this.
open (my $fh, '<', $passfile);
my $rootpass = <$fh>; chomp($rootpass); # Gets rid of newline
say "password: '$rootpass'";
答案 1 :(得分:0)
这一行
my $passfile = "$jobDir/\rootpass";
将放置一个回车字符 - 十六进制0D-其中\r
在字符串中。你想要的意思是
my $passfile = "$jobDir/rootpass";
该行
open ROOTPASS, '$passfile';
将尝试打开一个名为-wordrally的文件 - $passfile
。你想要
open ROOTPASS, $passfile;
或者,更好
open my $pass_fh, '<', $passfile or die $!;
以下是摘要
use strict;
use warnings;
my $jobdir = '/path/to/jobdir';
my $passfile = "$jobdir/rootpass";
print "file name = $passfile\n";
open my $pass_fh, '<', $passfile or die qq{Failed to open "$passfile" for input: $!};
my $rootpass = <$pass_fh>;
print "$rootpass\n";
file name = /path/to/jobdir/rootpass
Failed to open "/path/to/jobdir/rootpass" for input: No such file or directory at E:\Perl\source\rootpass.pl line 9.