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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.