0

i try to import huge text file (~5 million lines). I try with this script

aaa = perl('importFile.pl',fileName);

where "importFile.pl" is

use strict;
use warnings;
    while (my $row = <>) {
      chomp $row;
      print "$row\n";
    }

but nothing happens!. what is my mistake??? Or can you suggest similar (and fast) solution?

Matlab R2014a 64bit

claudio
  • 11
  • 2
  • 1
    Why do you have to use Perl? – sco1 Feb 09 '18 at 13:42
  • i'm looking for something fast and i think is one faster way to import this kind of file, but I'm open to other suggestion.. – claudio Feb 09 '18 at 14:44
  • Faster than *what*? What kind of data is in the file? What are you going to do with it? MATLAB has extensive [data import](https://www.mathworks.com/help/matlab/data-import-and-analysis.html) functionality, you're going to have to be more specific. – sco1 Feb 09 '18 at 15:12
  • I try using for loop + fgetl function with preallocation.. I import the file in one hour. To preallocate the araay I check the number of rows with perl script... in one second. When I say "faster" I mean something similar to this time. I do not know if I've made the idea... – claudio Feb 12 '18 at 08:40
  • Of course the Perl script takes one second, it’s not reading anything into RAM. Again, you need to be more specific. What is in the file? How are you reading it? – sco1 Feb 12 '18 at 10:35
  • the file is ASCII file (*.txt fil) – claudio Feb 13 '18 at 09:48
  • the file is an ASCII file ('*.txt'), where first row contains variable names, unit name the second one and data values for the rest. data values can be numeric or strings. each column has the same data type. I can do the first "raw" reading like char values using Perl, than translate in numeric value (with mex str2double version). This is my basic idea to speed up. what do you think about it? – claudio Feb 13 '18 at 10:00

1 Answers1

0

Iam not super familiar with perl but have worked with it alittle in the past.I'm guessing there is an issue with your loop, but like I stated i'm not a perl monk! Here is a program I used to read from a file and prints it:

#!/usr/bin/perl

use strict;
use warnings;

#Opens a file handler
open my $fh, '<', '/home/user/Desktop/ScriptForChangesets/ToBeRead.txt' or die "Can't open file";

#Prints the file contents
print do{local $/; <$fh>};

Hope this helps!

LazyTitan
  • 43
  • 9