in reply to help with cyrillic characters in odd places

Q2) How do I convince Path::Tiny to give me all these paths?
use strict;
use warnings;
use utf8;

use Test::More tests => 2;
use Path::Tiny;
use Encode ('decode');

my $dir = '/tmp/foo';
mkdir $dir unless -d $dir;
mkdir "$dir/eugene" or die $!;
mkdir "$dir/захват" or die $!;

my $pt = path ($dir);
my @children = $pt->children;
is (decode ('UTF-8', "$children1"), "$dir/eugene");
is (decode ('UTF-8', "$children[0]"), "$dir/захват");

$pt->remove_tree;

Your environment may use some other collation but the above works just fine for me.

(PS. You will have to fix up the line of the first test to put the square brackets back in. <pre> required as usual for the UTF-8 strings.)

Replies are listed 'Best First'.
Re^2: help with cyrillic characters in odd places
by Aldebaran (Curate) on Feb 07, 2019 at 00:44 UTC

    Thx, hippo, this syntax gets us started

    my @children = $pt->children;

    , but it seems to draw me away from Path::Tiny because @children appears to be a bunch of strings. (Progress is having them all there, so yay that.)

    children are /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/caption_filled.gif /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/за
    ва‚ /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/изоб€ажение /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/подписи /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/eugene
    dyetya is /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/caption_filled.gif
    dyetya is /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/захват
    Can't locate object method "basename" via package "/home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/захват" (perhaps you forgot to load "/home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/захват"?) at ./7.cw2.pl line 83.
    $ 
    

    I suppose one could pull out File::Basename, but that's a module I'm trying to abrogate.

    my @children = $vars{cw}->children;
    say "children are @children";
    
    foreach my $child (@children) {
      $child = decode( 'UTF-8', $child );
      say "dyetya is $child";
      next unless -d $child;
    
      my $base_dir = $child->basename;
      say "base dir is $base_dir";
      $vars{$base_dir} = path($child);
      say "dir is $vars{$base_dir}";
    
    }
    Update:

    I believe that the Path::Tiny way to do this is using the iterator method:

    my $iter = $vars{cw}->iterator; while ( my $next = $iter->() ) { say "next is $next"; my $next_decode = decode( 'UTF-8', $next ); my $base = $next->basename(); say "base is $base"; my $base_decode = decode( 'UTF-8', $base ); say "next decode is $next_decode"; say "base decode is $base_decode"; }
    next is /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/изоб€ажение
    base is изоб€ажение
    next decode is /home/bob/2.scripts/pages/7.cw/template_stuff/crosswords/изображение
    base decode is изображение
    
      but it seems to draw me away from Path::Tiny because @children appears to be a bunch of strings.
      say "children are @children";

      They only appear to be a bunch of strings because you've stringified them in the say statement.