princepawn has asked for the wisdom of the Perl Monks concerning the following question:

Gentlemen, the following line in a file:
NYCERS NYC Employees' Retirement System C
is failing when I use the following code to parse the file:
my $fh = new FileHandle "$dir/$file"; defined $fh or die "couldnt open $file: $!"; <$fh>; my %line; while (<$fh>) { my @line = map { s/^\s+//; s/\s+$//; s/\x0d//; $_; } ( quotewords("\t", 0, $_) ) ; $line[$FULL_NAME] =~ s<([^\x20\x21\x23\x27-\x3b\x3d\x3F-\x5B\x5D-\ +x7E])> <'&#'.(ord($1)).';'>seg; $line{$line[$ACRONYM]} = { type => $line[$TYPE], full_name => $line[$FULL_NAME] } ; } \%line;

And I believe it has to do with the single apostrophe on the line... any help is appreciated.

Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

Replies are listed 'Best First'.
Re: Text::Parsewords and lines with a single quote
by traveler (Parson) on Nov 25, 2002 at 16:05 UTC
    From the Parsewords documentation: The $keep argument is a boolean flag. If true, then the tokens are split on the specified delimiter, but all other characters (quotes, backslashes, etc.) are kept in the tokens. I think that means that your second argument to quotewords needs to be true to avoid the single quote.

    HTH, --traveler

Re: Text::Parsewords and lines with a single quote
by broquaint (Abbot) on Nov 25, 2002 at 15:46 UTC
    Escaping the single-quote works for me
    use Text::ParseWords; $s = q[NYCERS NYC Employees\' Retirement System C]; print join(", ", quotewords("\t", 0, $s)),$/; __output__ NYCERS, NYC Employees' Retirement System, C

    HTH

    _________
    broquaint