It did not. I've been whittling this SSCCE down from a river of mojibake and woe, my soaked and freezing body wondering where my skills to deal with such environments have been. Well, getting the logic from Path::Tiny wrong was one thing that had me beat. I was reading this as:
@lines = $file->lines;, which, I believe would produce different results. It's very difficult to diagnose path and file input problems from the net, but you and haukex have done exactly that. Thank you.
What can the OP do about misapprehension? (Open question) I would like to introduce a little bit of code to test whether I have these data represented correctly. I frequently find that I'm off by a pair of square brackets or quotes and commas. I'll use readmore tags for output then new source for the caller.
$ ./3.sscce.pl 1..1 number is 1 number is 8 ["abcdef", "abcdef", "abcde ", " bcdef"] inside first anonymous block index 1 out of range at ./3.sscce.pl line 34. # Looks like your test exited with 255 before it could output anything +. $ cat 3.sscce.pl
#!/usr/bin/perl -w use 5.011; use Path::Tiny; use lib "lib"; use Data::Dump; my $path_to_file = path( "lib", "1.txt" ); ### counterexample my @array = $path_to_file->slurp; my $number = scalar @array; say "number is $number"; ## read data into arrays properly my @better_array = $path_to_file->lines; my $number2 = scalar @better_array; say "number is $number2"; # 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 ); dd $out; ## tests use crossword2; use Test::More; { say "inside first anonymous block"; my $subset = getsubset( $out, "R1" ); is_deeply $subset, [ [ 'a' .. 'f' ] ]; say "exiting first anonymous block"; } dd $out; sub make_rectangular { my ( $lines, $maxrows, $maxlength ) = @_; my @out; my $rowcount=1; for my $line (@$lines) { my $trimmed = substr $line, 0, $maxlength; push @out, sprintf "%-*s", $maxlength, $trimmed; last if ++$rowcount>$maxrows; } return \@out; } __END__
What is being tested is whether the first row is a .. f . The getsubset subroutine is from Selecting Ranges of 2-Dimensional Data. I was able to replicate those results at the time. Other tests looked like:
{ my $subset = getsubset( $data, "R2C5:R4C8" ); print_aoa $subset; is_deeply $subset, [ [ 'e' .. 'h' ], [ 15, 66, 17, 18 ], [ 55, 56, 5 +7, 58 ] ]; $subset->[1][2] += 5; say "added 5 to a value"; } say "----------"; print_aoa $data; say "----------"; { my $subset = getsubset( $data, "C8:Cn" ); print_aoa $subset; is_deeply $subset, [ [ 8 .. 10 ], [ 'h' .. 'j' ], [ 18 .. 20 ], [ 58 .. 60 ] ]; $subset->[1][2] = 'X'; say "substitutes X"; }
So, Athanasius, when you ask what I desire...what I would like is to pass similar tests, but not with cyrillic, just nice plain ascii a, b, c's. I'm only looking for vectors, although some puzzles require only adjacency. Anyways, the crossword module is 204 lines: listing for xword pm. The function make_russian_crossword shows the pitiful and incomprehensible demoralization that prompted the need to get back to first principles.
Thanks all for comments,
2019-03-01 Athanasius changed one set of pre tags to code tags
In reply to Re^2: rectangularizing input to become array
by Aldebaran
in thread rectangularizing input to become array
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |