English 中文(简体)
每一行的文件增加一个额外空间
原标题:File is adding one extra space in each line
  • 时间:2010-06-10 16:06:21
  •  标签:
  • perl

我试图用推力补充阵列中的所有内容。 之后,i 储存在另一个档案中

但是,从档案开始,看到每个东西都有一个白人和平组织。

问题何在。

open FILE , "a.txt"

while (<FILE>)
{

  my $temp =$_;

  push @array ,$temp;

}
close(FILE);

open FILE2, "b.txt";
print FILE2 "@array";
close FILE2;
最佳回答

当你引用像以下几组变量:@array”时,它便与空间发生干扰。 这是你们的产出。 因此,如果你不需要或想要进行这种干涉,则不会援引。

现在让我把你的节目改写到现代的Perl。

use strict;
use warnings FATAL =>  all ;
use autodie qw(:all);

my @array;
{
    open my $in,  < ,  a.txt ;
    @array = <$in>;
}

{
    open my $out,  > ,  b.txt ;
    print {$out} @array;
}
问题回答

页: 1 这使得它成为一种扼杀性污染,对阵列而言,它相当于<条码>join($),@array)。 <代码>$>的缺省值是(猜测什么?)一个空间。

提 出

print FILE2 @array;




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签