Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Problem with accentued characters

Reply
Thread Tools

Problem with accentued characters

 
 
Pierre Thibault
Guest
Posts: n/a
 
      08-08-2004
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";
}
}

------------------------
Pierre
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      08-09-2004
Pierre Thibault wrote:
>
> 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:ath;
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
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert HTML special characters to the real characters with a Java script Stefan Mueller HTML 3 07-23-2006 10:09 PM
How to accept accentued characters JellyON Javascript 1 11-20-2005 11:03 AM
Encrypt accentued characters JellyON Javascript 3 11-06-2005 01:21 PM
Convert Raw Text Escaped Characters to Characters nicholas.wakefield@gmail.com Java 2 07-11-2005 09:17 PM
help-> xslt transformation to pdf (chinese characters changed to # characters) omegaman XML 1 09-21-2004 10:44 PM



Advertisments