Using
Perl to read text file on OS X can be tricky if combining files that
were generated using different programs. Especially it seems that
IGOR on is using DOS encoding for end of line than the standard OS X. Even after the files where copied onto a mac.
Thus if for example you'd like to convert a column file to a row using Perl, you should make sure what is the end of line char.
Here are a short example, reading a file that was generated in matlab and a file generated by a different perl program on OS X.
We are using the line separator variable:
$/
#!/usr/bin/perl -w
open(FOO,"<CCstats_SIE44"); # The file CCstats_SIE44 was generated by IGOR.
$/ = "\015\012";
@in = <FOO>;
chomp @in;
print STDOUT "CCstats\n";
print STDOUT join(" ",@in),"\n";
close(FOO);
Will result in the following output: (Where the file had originally each number in a separate line).
CCstats
12.77839 22.01258 35.00684 34.87996
However if the file was generated using Matlab, or perl on OS you may ignor the
$\ definition or set it to
"\012" as in:
open(FOO,"<Analysis/MCTW/sie_res.txt");
$/ = "\012";
@in = <FOO>;
chomp @in;
print STDOUT join(" ",@in);
close(FOO);
For more details check out:
http://www.sunsite.ualberta.ca/Documentation/Misc/perl-5.6.1/pod/perlport.html