I'm attempting to present an SSCCE. I realized that I can use directories on github, and I read somewhere that a good name for a default directory in perl development is 'lib'. I have a calling script which uses Path::Tiny to find an input file in 'lib'. The following link contains the entire source and input file: SSCCE (1.1 kB).

Update:In the time between when I posted the problem and when I have solutions, laden with tests, this workspace has grown to just under 5k. The first script 1.sscce.pl should still "work," but one can see how much distance we traveled by looking at 5.sscce.pl .

But one need not chase an external link to comment on the substance of my question. I'm a fortran then a C guy, so I'm alway tempted to go to external loops to set values in arrays. Likewise, the c technique of doing one char at a time is effective, but not extensible the way I desire. I do not seek solutions here that look like fortran or c. The perl solution is elegant and attainable.

Caller is pretty plain, but I'll put code and initial output between readmore tags:

$ pwd /home/bob/Desktop/SSCCE-master/sscce $ ls 1.sscce.pl lib $ cat 1.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" ); my $guts = $path_to_file->slurp; say "return1 is "; say "$guts"; my @lines = $path_to_file->slurp; say "return2 is "; say "@lines"; my $ref_lines = \@lines; my $width = 6; my $length = 4; my $ref_array = make_rectangular1( $guts, $width, $length ); #dd $ref_array; sub make_rectangular1 { my ( $guts, $width, $length ) = @_; my $ref_array = "nothing yet"; return $ref_array; } sub make_rectangular2 { my ( $ref_array, $width, $length ) = @_; my @new_array = @$ref_array; say "new array is "; say "@new_array"; #my $ref_array = "nothing yet"; return $ref_array; } __END__ $

Output is pretty clear:

$ ./1.sscce.pl return1 is abcdef abcdefg abcde bcdefgh bcd return2 is abcdef abcdefg abcde bcdefgh bcd $

What I would like is for these inputs to get trimmed to an array of the size specified by $width and $length . Spaces added/substituted on right if necessary to pad each vector to the same size. There's a sub stubbed out for each of the slurp possibilities.

Also, what character is it that renders an entire space dark?

Thanks for your comment,


In reply to rectangularizing input to become array by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.