Problem with accentued characters

Discussion in 'Perl Misc' started by Pierre Thibault, Aug 8, 2004.

  1. 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
    Pierre Thibault, Aug 8, 2004
    #1
    1. Advertising

  2. 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::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
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Aug 9, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    751
  2. Stefan Mueller
    Replies:
    3
    Views:
    32,951
    Stefan Mueller
    Jul 23, 2006
  3. omegaman
    Replies:
    1
    Views:
    555
    omegaman
    Sep 21, 2004
  4. JellyON

    Encrypt accentued characters

    JellyON, Nov 6, 2005, in forum: Javascript
    Replies:
    3
    Views:
    110
    JellyON
    Nov 6, 2005
  5. JellyON

    How to accept accentued characters

    JellyON, Nov 20, 2005, in forum: Javascript
    Replies:
    1
    Views:
    72
    JellyON
    Nov 20, 2005
Loading...

Share This Page