title: How do I write a file whose *filename* contains utf8 characters in Perl?
body: <p>I am struggling creating a file that contains non-ascii characters.</p>
  
  <p>The following script works fine, if it is called with <code>0</code> as parameter but dies when called with <code>1</code>.</p>
  
  <p>The error message is <em>open: Invalid argument at C:\temp\filename.pl line 15.</em></p>
  
  <p>The script is started within <code>cmd.exe</code>.</p>
  
  <p>I expect it to write a file whose name is either (depending on the paramter) <code>äöü.txt</code> or <code>äöü☺.txt</code>. But I fail to create the filename containing a smiley.</p>
  
  <pre><code>use warnings;
  use strict;
  
  use Encode 'encode';
  
  #   Text is stored in utf8 within *this* file.
  use utf8;
  
  my $with_smiley = $ARGV[0];
  
  my $filename = 'äöü' . 
    ($with_smiley ? '☺' : '' ).
     '.txt';
  
  open (my $fh, '&gt;', encode('cp1252', $filename)) or die "open: $!";
  
  print $fh "Filename: $filename\n";
  
  close $fh;
  </code></pre>
  
  <p>I am probably missing something that is obvious to others, but I can't find, so I'd appreciate any pointer towards solving this.</p>