Perl Filehandle Open截断文件(Perl Filehandle Open Truncates the File)
我正在编写我的第一个Perl程序,这是一个很糟糕的事情。 我很高兴地说,大部分内容都是有效的,搜索这个网站对我的大多数问题都有所帮助。
我正在处理由空格分隔值组成的大文件。 我向下过滤文件以仅显示其中一列中具有特定值的行,并将过滤后的数据输出到新文件。 然后我尝试将该文件的所有行都推送到一个数组中以用于循环。 这是一些代码:
my @orig_file_lines = <ORIG_FILE>; open MAKE_NEW_FILE, '>', 'newfile.dat' or die "Couldn't open newfile.dat!"; &make_new_file(\@orig_file_lines); ##Creates a new, filtered newfile.dat open NEW, "newfile.dat" or die "Couldn't open newfile.dat!"; my @lines; while(<NEW>){ push(@lines,$_); } printf("%s\n", $lines[$#lines]); ##Should print entirety of last line of newfile.dat
问题有两个:1。$#lines = 24500这里新创建的文件(newfile.dat)实际上有24503行(所以它应该是24502),2。printf语句返回截断的行24500,切断该行过早地大约两列。
每个其他行,例如$ lines [0-24499],即使它比$ lines [24500]更宽,也会成功打印整行,所以特定行的长度(它们都很长)不是问题。 但这几乎就好像阵列变得太大了,因为它切断了一条线的一部分,然后是接下来的两条线。 如果是这样,我该怎么做呢?
I am writing my first Perl program and it's a doozy. I'm happy to say that everything has been working for the most part, and searching this website has helped with most of my problems.
I am working with a large file composed of space separated values. I filter the file down to display only lines with a certain value in one of the columns, and output the filtered data to a new file. I then attempt to push all of the lines of that file into an array to use for looping. Here's some code:
my @orig_file_lines = <ORIG_FILE>; open MAKE_NEW_FILE, '>', 'newfile.dat' or die "Couldn't open newfile.dat!"; &make_new_file(\@orig_file_lines); ##Creates a new, filtered newfile.dat open NEW, "newfile.dat" or die "Couldn't open newfile.dat!"; my @lines; while(<NEW>){ push(@lines,$_); } printf("%s\n", $lines[$#lines]); ##Should print entirety of last line of newfile.dat
The problem is twofold: 1. $#lines = 24500 here when the newly created file (newfile.dat) actually has 24503 lines (so it should be 24502), 2. the printf statement returns a truncated line 24500, cutting off that line prematurely by about two columns.
Every other line, e.g. $lines[0-24499], will successfully print the entire line even when it is wider than $lines[24500], so the length of that particular line (they're all long) is not the problem. But it is almost as if the array has gotten too large somehow, since it cut off part of one line, and then the next two lines. If so, how do I combat this?
原文:https://stackoverflow.com/questions/20054367
最满意答案
使用字符串[defBackColor] =“'#FFFFF7'”
Use string [defBackColor]="'#FFFFF7'"
相关问答
更多-
Convert.ToInt32("3A", 16) Convert.ToInt32("3A", 16)
-
尝试这个: 指示: @Directive({ selector: '[random]', host: { '(mouseenter)': 'onMouseEnter()', //just for test } }) export class RandomDirective { @Input() text: string; //method for test onMouseEnter() { ...
-
我从未见过一个。 虽然使用微调器做十六进制不应该太难 - 要么使用0x00 - 0xFF作为值的选择框,要么执行0到256的常规微调器并在spin()事件中转换为十六进制。 Ended up solving this by writing custom format and parse handlers, as well as overriding the keypress event to enalble the user to type in hex digits: // Functio ...
-
是的,这只是一个整数。 它的十六进制只在显示给我们阅读时才是重要的。 Yes, it's just an integer. The hexadecimal aspect of it is only important when it's displayed for us to read.
-
如何将没有相应ASCII的HEX字符作为输入传递给C程序(How to pass HEX character with no corresponding ASCII to a C program as input)[2022-07-01]
要以编程方式解决问题,可以在shell脚本中使用expect 。 I was able to resolve this issue by escaping the null character with Ctrl+ @ -
使用字符串[defBackColor] =“'#FFFFF7'” Use string [defBackColor]="'#FFFFF7'"
-
NASM内存操作数使用方括号表示解除引用。 例如,您将需要: mov al, [HNUM] div byte [D] mov [HNUM], al NASM手册解释了这一点。 RTFM! 如果没有括号,标签将被视为等于内存位置地址的立即操作数。 第一行没有语法错误,但导致al加载HNUM地址的低字节。 不是你想要的。 div是一个错误,因为8086没有指示按立即数量划分。 mov是无稽之谈,因为你无法写入直接值。 所以错误消息告诉你什么是错的。 在引用的行中,操作数不符合其指令。 ...
-
您已将hexes作为字符串,因此您需要将它们转换为无符号字符(一个字节),然后才能将它们写入文件。 #include
#include #define ishexchar(c) (c>='A' && c<='F') || (c>='a' && c<='f') #define toupper(c) c - 32 #define isupper(c) c>='A' && c<='F' unsigned char hexconv(const char* str, int ... -
此代码使DE在ASCII中具有十六进制数,并在A中将其转换为二进制。它假定DE是有效的十六进制数,并使用大写的“A”到“F”。 如果使用小写字母或者在'0','9'和'A'之外的任何ASCII字符,它将失败。''F'。 HexToNum ld a,d call Hex1 add a,a add a,a add a,a add a,a ld d,a ld a,e ...
-
long i = Long.parseLong("f8004896", 16); System.out.println(i); System.out.println(Integer.MAX_VALUE); 输出: 4160768150 2147483647 long i = Long.parseLong("f8004896", 16); System.out.println(i); System.out.println(Integer.MAX_VALUE); Output: 4160768150 21 ...