-------------8<---------------------
forgive my naivety here but ive never had to use Unicode before.

I learned many years ago how to open a simple ascii file using perls open.

       open (IN, ‘infile.txt’);

then read records out of the ascii file.

       while ($rec = <IN>) {
                        print $rec;
       }

but today I wanted to write a perl script to evaluate the data from a text
file that gets created when one runs the Microsoft ‘msinfo32.exe’ program.

       msinfo32.exe /report msinfo.txt (this will dump vital system info to
a text file)
       
the problem here is that the ‘msinfo.txt’ file is not written in (single
byte per character, ascii) format.  instead the first two bytes of the file
happen to be (hexFF)(hexFE).  Beyond the first two bytes, each human
readable ascii character is represented with TWO BYTES, (hex-ascii character
value)(hex00)

I assume this is some form of Unicode encoding.  though I do not know the
type.  

if anyone out there knows what kind of encoding this is, it would be
wonderful to know the encoding type Microsoft has used here.

in addition, if anyone knows how to modify the following block so that I can
effectively, read the records of this file, and convert the read record into
‘plain old ascii’ encoding – I would be most appreciative.

essentially, this is what I am aiming to do;

       open (IN, ‘infile.txt’);
       while ($rec = <IN>) {
                  
convert_$rec_from_its_current_encoding?_to_simple_ascii_encoding; <<<<<<<<<<
the magic code would go here
                        print $rec;
       }
-------------8<---------------------

Here's the preferred way of opening files along with the magic tr operator:

use strict;
use warnings;
use Fatal qw( open );

my $file = 'msinfo.txt';

open my $FILE, '<', $file;
while ( <$FILE> )
{
    tr/\x20-\x7f//cd;

    print "$_\n";
}
close $FILE;


__END__

There's a suitable one liner on perlmonks:
http://209.85.173.132/search?q=cache:eUhPlTjCV28J:www.perlmonks.org/%3Fnode_
id%3D619792+perl+tr+non+ascii&cd=2&hl=en&ct=clnk&gl=au

But being Windows it won't allow in place editing, hence the need for a
move.

Just in

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to