Re: NSString encoding and perl script encoding
Re: NSString encoding and perl script encoding
- Subject: Re: NSString encoding and perl script encoding
- From: Sherm Pendley <email@hidden>
- Date: Thu, 1 Feb 2007 11:30:21 -0500
On Feb 1, 2007, at 11:15 AM, Chris Ridd wrote:
On 1/2/07 3:34, "David Brennan" <email@hidden> wrote:
Hi,
I am sending text from my NSString to a perl script using a NSPipe,
and I'm trying to read the result from the script using a pipe.
When I
send the text I use the encoding NSUTF8StringEncoding to create a
NSData object. When I read the result from the pipe, I also use
NSUTF8StringEncoding to convert the NSData to NSString.
At the start of my script I tell it to use 'utf8', see below.
But when I try to create the NSString from the NSData that is sent
back from the script, it fails. It seems that the encoding is
incorrect.
I am working on Tiger. What encoding should I use?
Thanks,
Dave.
use encoding 'utf8';
while (defined($line = <STDIN>))
{
print $line
}
A somewhat superficial glance at 'man perlunicode' suggests that "use
encoding 'utf8'" really just changes the way your script is encoded.
That's the behavior of the "use utf8" pragma, not "use encoding 'utf8'".
From The Fine "perldoc encoding" Manual:
The encoding pragma also modifies the filehandle layers of STDIN and
STDOUT to the specified encoding.
Note that STDERR is not modified, nor is the default changed for any
file handles you open yourself. I suspect that the problem script is
actually doing more than the simple example above.
But a careful read of the above manpages is recommended :-)
Indeed. :-)
sherm--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden