[如何去除换行符]处理文本的求助!

[如何去除换行符]处理文本的求助!

有一文本如

bash-2.05# more time.txt
1.438856
0.47366
0.482491
0.838388
2.484905
0.551992
4.551946
0.442001
0.446499

$count = 1;
$data = "[";
while ($count < @datatt) {
        $data .= $datatt[$count-1].",";
        $count++;

}
$data .= $datatt[$count-1]."]";

可以实现成
[1.438856
,0.47366
,0.482491
,0.838388
,2.484905
,0.551992
,4.551946
,0.442001
,0.446499
]

为什么换行了?  如何成为一个行?
chomp
或者 =~ s/^\s+|\s+$//g;
具体怎么用,谢谢!   加在哪里,谢谢!
if(open(TT,"tt")){

@datatt =<TT>;
}
$count = 1;
$data = "[";
while ($count < @datatt) {
        $data .= $datatt[$count-1].",";
        $count++;

}
$data .= $datatt[$count-1]."]";
chomp @datatt;
#!/usr/bin/perl

use File::Basename;
use lib dirname($0);

use perlchartdir;

# The data for the line chart
my $data = [1.438856,0.47366,0.482491,0.838388,2.484905,0.551992];


这里的$data  和以下的$data 有什么区别? chomp @datatt;
if(open(TT,"tt"){

@datatt =<TT>;
}
$count = 1;
$data = "[";
while ($count < @datatt) {
        $data .= $datatt[$count-1].",";
        $count++;

}
$data .= $datatt[$count-1]."]";


为何画图的时候就会出现错误:
# The labels for the line chart
my $labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
    "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"];

# Create a XYChart object of size 250 x 250 pixels
my $c = new XYChart(250, 250);

# Set the plotarea at (30, 20) and of size 200 x 200 pixels
$c->setPlotArea(30, 20, 200, 200);

# Add a line chart layer using the given data
$c->addLineLayer($data);

# Set the labels on the x axis.
$c->xAxis()->setLabels($labels);

# Display 1 out of 3 labels on the x-axis.
$c->xAxis()->setLabelStep(3);

# output the chart
binmode(STDOUT);
print "Content-type: image/png\n\n";
print $c->makeChart2($perlchartdir:NG);


错误为
bash-2.05# perl line.pl
Error converting argument 1 to type 11DoubleArray
*** Stack back trace ***
calling XYChart::addLineLayer at line.pl:44

似乎 my $data = [1.438856,0.47366,0.482491,0.838388,2.484905,0.551992];   是ARRAY(0x229a4)

搞不懂。
比较乱来,和我以前一样
my $data = [1.438856,0.47366,0.482491,0.838388,2.484905,0.551992];
$data 指向一个匿名 array

$data->[0]  ....
@{$data}[0] ....
这种形式看看

如果想把 1.438856,0.47366,0.482491,0.838388,2.484905,0.551992 放到一个数组里
应该写 my @data = (1.438856,0.47366,0.482491,0.838388,2.484905,0.551992);
还有一种好的方法
$data=\ @datatt;