开发者

Unable to read RTF file using Perl on Mac

I'm trying Perl on Mac. I have to read an RTF text file. the content of the file is "36" (without double quotes). thats it, just two characters.

Here is the code I have to read it.

#!/usr/bin/perl
use strict;
use warnings;

my $file = "verInfo.rtf";

unless(open FILE, $file) {
    # Die with error message
    # if we can't open it.
    die "\nUnable to open $file\n";
}

my $oldversion = <FILE>;

print "conent is $oldversion";

close FILE;

Remember all I want is to read the value 36 from file and store it as a integer in $oldversion

But when I read the file and print it, it prints following

conent is {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoa开发者_如何转开发subrtf360

Im not able to read 36.


You're not reading a text file, you're reading an RTF file. You made the file with TextEdit, right? TextEdit saves things as text/rtf rather than text/plain by default, if you want to save the file as plain text you should use "Format | Make Plain Text" (AKA Shift-Cmd-T) before you save it; then you'll get a simple text file with just your "36" in it.


The text is there:

{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
                                                ^^

You have an RTF file. Use an RTF parser

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜