Dear monks, A million thanks for your help so far. I have taken the most practical advice given here and have added the two lines regarding encoding into the program. An illustrative program with the text I am trying to parse are included below.
I am working in a windows environment, and use the dos prompt to call the script and .txt file that the above text is saved as. Unfortunately, the problem remains. Any further suggestions?
#!/usr/bin/perl
use open IN => ':encoding(cp1252)';
use open OUT => ':utf8';
use Getopt::Std;
our ($opt_f);
getopts('f:');
if($opt_f){
openFile ("$opt_f");
while (my $line = <FILE>) {
chomp ($line);
#the following line illustrates that what is being
#read in is transformed from the original text
print $line;
#if the part in the reg exp below "(État)" is removed, then
#the reg exp matches and $1 is printed correctly, but not
#with this kept in there
if ($line=~ /Number\s+of\s+Observations\s+Used\s+(\d+)\s+(État)/){
print "$1";
print "$2";
}
}
}
Here is a small illustrative piece of text I am trying to parse using the -f option:
Le Système SAS 243
09:11 Monday, October 29, 2007
The PHREG Procedure
Informations sur le modèle
Data Set WORK.PSEUDOCONTSAS
Dependent Variable time
Censoring Variable affstat
Censoring Value(s) 0
Ties Handling DISCRETE
Number of Observations Read 1162
Number of Observations Used 332
État de convergence
|