andalou has asked for the wisdom of the Perl Monks concerning the following question:

I'm using perl 5.12.4 on windows 7 and I know that there is a package,
Wild.pm, which allows to expand wildcard arguments, but it doesn't work
with files with Chinese characters in their filenames.

Suppose I have the following files:

chair.txt
table.jpg
song自然之歌.txt

and the following perl code:

require Wild; foreach (@ARGV) { print "$_\n"; }

If I supplied *.txt to it, it only outputs chair.txt but not
song自然之歌.txt

Many thanks in advance

  • Comment on How to expand wildcard arguments supplied to programs with perl on windows?
  • Download Code

Replies are listed 'Best First'.
Re: How to expand wildcard arguments supplied to programs with perl on windows?
by atcroft (Abbot) on Aug 17, 2012 at 02:02 UTC

    I don't know about the Wild.pm module you were using, but I was able to get results similar to what you indicated you expected with the following code:

    use strict; use warnings; foreach my $pattern (@ARGV) { foreach (glob($pattern)) { print qq{$_\n}; } }

    This was called from a Windows Command Prompt using Strawberry Perl as follows: perl test.pl *.txt I used a loop for @ARGV to allow for multiple patterns to be specified on the command line, to give a little extra flexibility.

    Hope that helps.

      Thanks, but it doesn't work if a file has Chinese characters in its
      filename, as in song自然之歌.txt

        The Perl file system calls and Unicode don't mix particularly well on file systems that don't encode their filenames as UTF-8. See for example Check if unicode directory exists.