#!/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__