$ ./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__
####
{
my $subset = getsubset( $data, "R2C5:R4C8" );
print_aoa $subset;
is_deeply $subset, [ [ 'e' .. 'h' ], [ 15, 66, 17, 18 ], [ 55, 56, 57, 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";
}