I was just giving this code as an example. If I could print the line, before
and after it was edited then I can easily modify it to edit the file.

I tried the the code that you suggested without editing anything (because
the edit did not work). In other words I just tried to read in the Unicode
and print out the lines as I converted them to ANSI, essentially:
        my $line = fromunicode($_);
        print $line;
This prints the first line but all other lines are blank (or just a CR or
LF).

The binary file has \x00 after every character except for the first two
characters in the file which are \xFF \xFE. I have attached the binary file
if someone would not mind looking at it helping me edit this file with Perl.

Thank you.

Kevin Burton
[EMAIL PROTECTED]



-----Original Message-----
From: Ned Konz [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 08, 2000 12:54 PM
To: Perl-Win32-Users Mailing List
Cc: Perl-Win32-Users Mailing List
Subject: Re: Finding and replacing a UNICODE string.


[EMAIL PROTECTED] wrote:
> 
> I have tried the below perl script to modify the major version number in a
> Unicode text file.

Well, a script that just prints one line if it matches won't edit a file
properly.
You probably want a print for every line, anyhow.

> It seems that the substitution never happens as the
> 'print' statement in the script below simple echoe the contents of the
line.
> Any ideas as to what I am doing wrong? The Unicode file looks something
> like:

>                my $number = $1;
>                $number = tr/\x00//d;

You probably wanted =~ as an operator in the tr/// line.

>                $number++;
>                join '',
>                map "$_\x00",
>                split //,
>                'ExeVerMajor\\=' . $number . '\\;'

That's pretty baroque. Better to make a tounicode() function and use
regular Perl
expressions (assuming you don't have anything other than 8-bit
characters)
(note that these are much faster than your map/split/etc):

sub tounicode { my $s = shift; pack('v*', unpack('c*', $s)) }
sub fromunicode { my $s = shift; pack('c*', unpack('v*', $s)) }

while (<>)
{
        my $line = fromunicode($_);
        # do processing as normal with Perl here:
        $line =~ s/whatever/whateverelse/;
        print tounicode($line);
}

Or am I missing something about your data? Has it always got NUL chars
as the second
byte?

-- 
Ned Konz
currently: Stanwood, WA
email:     [EMAIL PROTECTED]
homepage:  http://www.bike-nomad.com

---
You are currently subscribed to perl-win32-users as:
[EMAIL PROTECTED]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

HelloJava.vjp

Reply via email to