CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Convert txt file to ASCII

 



britanb
New User

Apr 20, 2010, 6:41 PM

Post #1 of 8 (1746 views)
Convert txt file to ASCII Can't Post

Hello,

I have a code that generates a .txt file, would you know how can I convert that .txt file to a ASCII format?


rovf
Veteran

Apr 21, 2010, 12:40 AM

Post #2 of 8 (1737 views)
Re: [britanb] Convert txt file to ASCII [In reply to] Can't Post

???? What format is the .txt file in? UTF-8 plain text? HTML? JPEG???


britanb
New User

Apr 21, 2010, 1:24 AM

Post #3 of 8 (1728 views)
Re: [rovf] Convert txt file to ASCII [In reply to] Can't Post

Thanks for the response. It's currently in ANSI format.


shawnhcorey
Enthusiast


Apr 21, 2010, 6:03 AM

Post #4 of 8 (1719 views)
Re: [britanb] Convert txt file to ASCII [In reply to] Can't Post

ANSI stands for American National Standards Institute. They have many, many standards. Which one of these are you talking about?

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


rovf
Veteran

Apr 21, 2010, 8:42 AM

Post #5 of 8 (1714 views)
Re: [britanb] Convert txt file to ASCII [In reply to] Can't Post

In addition to what shawnhcorey mentioned, it should be noted that Microsoft in their inscrutable wisdom, adopted the term to refer to a set of encoding systems (indeed largely based on some ANSI standard), which they call "ANSI code page". You find pointers to them at

http://en.wikipedia.org/wiki/Code_page#Windows_.28ANSI.29_code_pages

And here you have the ASCII code table:

http://www.asciitable.com/

In any case, the ANSI pages comprise a larger character set than ASCII, so you will have to think of a way what to do with those characters which can't be mapped.


britanb
New User

Apr 22, 2010, 4:55 AM

Post #6 of 8 (1690 views)
Re: [rovf] Convert txt file to ASCII [In reply to] Can't Post

Sorry if I'm not making sense here. Basically what im doing is that I have a perl script that automatically creates .KCM files or code modules for K2 2003(3rd party software). The problem is that when it gets created through the script it seems that it is not being recognized by that K2 2003. So what our hunch was that it follows a certain format, so we checked the .KCM files originally generated by the K2 2003 (Not by the perl script) through opening the file through notepad. And we were surprised that it had a different format when it is opened in notepad as compared opening it with the software.

Below is the sample code.

 L S R D L C o d e M o d u l e L S R D L C o d e M o d u l e 


my friend adviced that it was in ANCII(but we are not sure what type). Because of this, we are attempting to manipulate our script to convert our script generated kcm file to have the same format as above.

Let me know if i make sense here. We are already thinkin to find another alternative... Please advice


rovf
Veteran

Apr 23, 2010, 2:44 AM

Post #7 of 8 (1666 views)
Re: [britanb] Convert txt file to ASCII [In reply to] Can't Post

Well, first of all, if there seems to be a problem with the format, Notepad would pretty much the last utility I would use to check what's in a file. Better to use a text editor which also permits hexadecimal display (such as jEdit or PsPad - the latter is only available on Windows).

From Perl, you can read any file in Binary, which means that the real task you need to face is finding out *how* the file needs to be transformed; i.e. the principal problem is that of knowing the encoding of the original file, which is not a Perl problem. Once this has been established, we can look further what you need to do to translate.

For instance, if you find out that the original file is UTF-8 incoded, you just would need to use the :utf8 layer to read the file. If it is, however, a "unusual" encoding, you would have to program it by yourself.


britanb
New User

May 4, 2010, 1:39 AM

Post #8 of 8 (1547 views)
Re: [rovf] Convert txt file to ASCII [In reply to] Can't Post

Thanks for the advice! This is noted. So far we are just ignoring files with the weird format. I'll update you soon if we found a resolution for this.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives