Problem with accentued characters

  • Thread starter Pierre Thibault
  • Start date
P

Pierre Thibault

Hello,

I am having problems with a perl script. The fellowing script is
working well except for directory or file names using accented
characters. The last line (!system...) is giving me errors when I'm
using the result from the 'find' command if the file or the directory
contain accented characters. The error is "No such file or directory".

I'm using Perl 5.0 version 8 subversion 1 RC3 on Mac OS 10.3.4.

I really don't know how to solve this problem. Any help would be
appreciated.

#!/usr/bin/perl
#
# Create a list of files with their MD5 sums

use strict;

`mkdir -p /Users/pierreth/M5`;

my @path_list = ((split /:/, $ENV{"PATH"}), "/Applications");
for(@path_list) {
my $file_name_for_path = $_;
$file_name_for_path =~ s#/#-#g;
$file_name_for_path =~ s#^-##;
my $save_path = "/Users/pierreth/M5/$file_name_for_path";
`rm $save_path -f > /dev/null 2>&1`;
print "Now processing $file_name_for_path\n";
for(`find -L $_ -type f`) {
chomp;
s#\\#\\\\#g; # Paying attention to special character like \
s#'#\\'#g; # or '
!system ("md5sum '".$_."' >> '".$save_path."'") or die "Error $_
$save_path";
}
}
 
J

John W. Krahn

Pierre said:
I am having problems with a perl script. The fellowing script is
working well except for directory or file names using accented
characters. The last line (!system...) is giving me errors when I'm
using the result from the 'find' command if the file or the directory
contain accented characters. The error is "No such file or directory".

While Perl is a good "glue" language it is better to use Perl's built-in
features and modules for more efficiency and control.

I'm using Perl 5.0 version 8 subversion 1 RC3 on Mac OS 10.3.4.

I really don't know how to solve this problem. Any help would be
appreciated.

#!/usr/bin/perl
#
# Create a list of files with their MD5 sums

use strict;

`mkdir -p /Users/pierreth/M5`;

my @path_list = ((split /:/, $ENV{"PATH"}), "/Applications");
for(@path_list) {
my $file_name_for_path = $_;
$file_name_for_path =~ s#/#-#g;
$file_name_for_path =~ s#^-##;
my $save_path = "/Users/pierreth/M5/$file_name_for_path";
`rm $save_path -f > /dev/null 2>&1`;
print "Now processing $file_name_for_path\n";
for(`find -L $_ -type f`) {
chomp;
s#\\#\\\\#g; # Paying attention to special character like \
s#'#\\'#g; # or '
!system ("md5sum '".$_."' >> '".$save_path."'") or die "Error $_
$save_path";
}
}

Untested!

#!/usr/bin/perl
#
# Create a list of files with their MD5 sums

use warnings;
use strict;
use File::Find;
use File::path;
use Env '@PATH';
use Digest::MD5 'md5_hex';

my $dir = '/Users/pierreth/M5';

-d $dir or eval { mkpath( $dir ) };
die "Cannot create $dir: $@" if $@;

for my $path ( @PATH, '/Applications' ) {
( my $file_name_for_path = $path ) =~ s!^/!!;
$file_name_for_path =~ tr!/!-!;
my $save_path = "$dir/$file_name_for_path";

open my $MD5, '>', $save_path or die "Cannot open $save_path: $!";
print "Now processing $file_name_for_path\n";

find( sub {
return unless -f;
local $/;
open my $FILE, '<', $_ or die "Cannot open $_: $!";
binmode $FILE;
print $MD5 md5_hex( <$FILE> ), " $_\n";
}, $path );
}

__END__



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top