James Edward Gray II wrote:
> On Apr 19, 2010, at 3:31 AM, Brian Candler wrote:
> 
>> Code to demonstrate:
>> 
>>  str = "\xff"
>>  File.open("out1","w") { |f| f.puts str }
>>  File.open("out2","w:UTF-8") { |f| f.puts str }
>> 
>> Line 2 will never raise an exception, regardless of the content or the 
>> encoding of str, and regardless of environment variable settings. It 
>> just writes the string to the file.
> 
> That's grossly inaccurate.  You may not have write permission to the 
> file, the volume you are trying to place the file on may be out of 
> space, etc.

Of course syscalls can fail due to insufficient resources and other 
system-level problems. I'm talking about the normal flow of execution.

The point remains: Benoit said that one way to make your program immune 
to influence from environment variables was to use 
File.open("myfile.ext","w:UTF-8"). I was trying to highlight that advice 
is incorrect, because the regular File.open("myfile.ext","w") is immune 
to environment variables already. Furthermore, "w:UTF-8" can crash in 
the normal flow under more circumstances than "w" - and those 
circumstances depend on string contents and encodings, which _can_ be 
affected by environment variables.
-- 
Posted via http://www.ruby-forum.com/.