$ echo $PATH
/home/bob/perl5/bin:/home/bob/2.scripts/pages/9.cw/template_stuff/crosswords/sscce:/home/bob/bin:/home/bob/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ pwd
/home/bob
$ ./5.sscce.pl
bash: ./5.sscce.pl: No such file or directory
$
####
$ ls -R
.:
1.sscce.pl 5.sscce.pl lib mydata
./lib:
1.txt crossword2.pm
./mydata:
1.out.txt 1.txt
$
####
$ ./5.sscce.pl
1..16
before conversion
["abcdef", "abcdef", "abcde ", " bcdef"]
after conversion
[
["a" .. "f"],
["a" .. "f"],
["a" .. "e", " "],
[" ", "b" .. "f"],
]
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
char is █
inside first anonymous block
ok 10
exiting first anonymous block
----------
[
["a" .. "f"],
["a" .. "f"],
["a" .. "e", " "],
[" ", "b" .. "f"],
]
----------
[["a"], ["a"], ["a"], [" "]]
ok 11
[["a"], ["a"], ["a"], ["\x{2588}"]]
exit 2nd
----------
[
["a" .. "f"],
["a" .. "f"],
["a" .. "e", " "],
["\x{2588}", "b" .. "f"],
]
----------
ok 12
----------
ok 13
----------
ok 14
[
["a" .. "f"],
["a", "q", "c" .. "f"],
["a" .. "e", " "],
["\x{2588}", "b" .. "f"],
]
----------
let's blacken the space in the last column
[["f"], ["f"], [" "], ["f"]]
ok 15
[["f"], ["f"], ["\x{2588}"], ["f"]]
----------
let's see if it shows in row 3
ok 16
[["a" .. "e", "\x{2588}"]]
----------
abcdef
aqcdef
abcde█
█bcdef
----------
abcdef
aqcdef
abcde█
█bcdef
(97 .. 102, 10)
(97, 113, 99 .. 102, 10)
(97 .. 101, 9608, 10)
(9608, 98 .. 102, 10)
####
#!/usr/bin/perl -w
use 5.011;
use Path::Tiny;
use lib "lib";
use Data::Dump;
binmode STDOUT, 'utf8';
use crossword2; #available on github
my $path_to_file = path( "mydata", "1.txt" );
my $path_to_output = path( "mydata", "1.out.txt" );
# moving forward with slurp method
my $input = $path_to_file->slurp;
$input =~ s/\t/ /g;
my @lines = split /\n/, $input;
my $out = make_rectangular( \@lines, 4, 6 );
say "before conversion";
dd $out;
$out = [ map { [ split // ] } @$out ]; #convert reference
say "after conversion";
dd $out;
## tests
use Test::More tests => 16;
# unchanged from haukex's tests
is_deeply rangeparse("R1"), [ 1, 1, 1, -1 ];
is_deeply rangeparse("C1"), [ 1, 1, -1, 1 ];
is_deeply rangeparse("Rn"), [ -1, 1, -1, -1 ];
is_deeply rangeparse("Cn"), [ 1, -1, -1, -1 ];
# new values
is_deeply rangeparse("C1:C3"), [ 1, 1, -1, 3 ];
is_deeply rangeparse("R2:Rn"), [ 2, 1, -1, -1 ];
is_deeply rangeparse("C3:Cn"), [ 1, 3, -1, -1 ];
is_deeply rangeparse("R1C3:R1C5"), [ 1, 3, 1, 5 ];
is_deeply rangeparse("R4C1:R4C3"), [ 4, 1, 4, 3 ];
# initialize full block character
my $char = "\N{FULL BLOCK}";
say "char is $char";
{
say "inside first anonymous block";
my $subset = getsubset( $out, "R1" );
is_deeply $subset, [ [ 'a' .. 'f' ] ];
say "exiting first anonymous block";
}
say "----------";
dd $out;
say "----------";
{
my $subset = getsubset( $out, "C1" );
dd $subset;
is_deeply $subset, [ ['a'], ['a'], ['a'], [' '] ];
$subset->[3][0] = $char;
dd $subset;
say "exit 2nd";
}
say "----------";
dd $out;
say "----------";
is_deeply $out,
[
[ "a" .. "f" ],
[ "a" .. "f" ],
[ "a" .. "e", " " ],
[ "\x{2588}", "b" .. "f" ],
];
say "----------";
{
my $subset = getsubset( $out, "R2C2" );
is_deeply $subset, [ ['b'] ];
$subset->[0][0] = 'q';
}
say "----------";
is_deeply $out,
[
[ "a" .. "f" ],
[ "a", "q", "c" .. "f" ],
[ "a" .. "e", " " ],
[ "\x{2588}", "b" .. "f" ],
];
dd $out;
say "----------";
say "let's blacken the space in the last column";
{
my $subset = getsubset( $out, "Cn" );
dd $subset;
is_deeply $subset, [ ['f'], ['f'], [' '], ['f'] ];
$subset->[2][0] = $char;
dd $subset;
}
say "----------";
say "let's see if it shows in row 3";
{
my $subset = getsubset( $out, "R3" );
is_deeply $subset, [ [ 'a' .. 'e', $char ] ];
dd $subset;
}
say "----------";
print_aoa($out);
say "----------";
print_aoa_utf8($out);
done_testing();
# output
my $file_handle = $path_to_output->openw_utf8();
for my $row (@$out) {
my $line = join( "", @{$row}, "\n" );
dd unpack 'C*', $line;
$file_handle->print($line);
}
__END__