M
Matthew Crema
Hello,
I'm brand new to Perl. I spent the last few weeks reading the "Llama"
and I want to get started now. This question is more for a beginner's
curiosity than an actual application.
Say I have 1000 text files called:
data1.dat
data2.dat
data3.dat
..
..
..
data1000.dat
Each of these files has 32768 integer numbers (between -100 and 100)
like so:
10
-20
-14
..
..
..
90
Say I issue the command:
$cat *.dat > one_large_file
This takes about 1.5 seconds.
However, the Perl script I wrote takes 28 seconds . Am I doing
something wrong? My guess is that it has something to do with type
conversions behind the scenes.
Thanks.
-Matt
Here's the code:
#! /usr/bin/perl -w
use strict;
my $NFILES = 1000;
for (my $i=1;$i<=$NFILES;++$i) {
my $filename = "data$i.dat";
open (DATA, "< $filename") or die "Cannot open file: $!";
while (my $line = <DATA>){
print $line;
}
close DATA;
}
I'm brand new to Perl. I spent the last few weeks reading the "Llama"
and I want to get started now. This question is more for a beginner's
curiosity than an actual application.
Say I have 1000 text files called:
data1.dat
data2.dat
data3.dat
..
..
..
data1000.dat
Each of these files has 32768 integer numbers (between -100 and 100)
like so:
10
-20
-14
..
..
..
90
Say I issue the command:
$cat *.dat > one_large_file
This takes about 1.5 seconds.
However, the Perl script I wrote takes 28 seconds . Am I doing
something wrong? My guess is that it has something to do with type
conversions behind the scenes.
Thanks.
-Matt
Here's the code:
#! /usr/bin/perl -w
use strict;
my $NFILES = 1000;
for (my $i=1;$i<=$NFILES;++$i) {
my $filename = "data$i.dat";
open (DATA, "< $filename") or die "Cannot open file: $!";
while (my $line = <DATA>){
print $line;
}
close DATA;
}