in reply to Re^2: rectangularizing input to become array
in thread rectangularizing input to become array

So there's the base directory of the script. I wouldn't want output there. ... would you rather put such a thing on our one and only subdirectory or split input and output into deparate directories?

Here's an idea for how to handle a script with a library.pm file or two that goes with it:

Should I go update that on the original post?

I think in this case you don't need to, it's just for future reference, thanks.

in your code tags you've included the command-line invocations that I'd have to trim
I tend to think that it provides context ... Might pre tags work here?

Yes you're right - I didn't mean to make it sound like it's not a good idea, context can certainly be useful in some cases - the main point was not to put it in the same <code> tag as the code, to make downloading easier. <pre> tags have the issue that HTML and PerlMonks special characters have to be escaped (as you can see your <pre> tag has been rendered with links in it), so two separate sets of <code> tags work. Or, here's how I might have written that post (note you can use <code> tags in paragraphs as well):

Here is the script 3.rm.pl, which I run via ./3.rm.pl:

#!/usr/bin/perl -w use 5.011; ...

And here is the output:

["abcdef", "abcdefg", "abcde", " bcdefgh", " bcd "] ["abcdef", "abcdef", "abcde ", " bcdef"] ...

Also, command lines like cat or perl script.pl are simple enough that we usually don't need to see them, it only becomes important when there are additional arguments involved. (And for some questions, it can be relevant whether a script was invoked as ./script.pl or perl script.pl, but that's not too often.)

What I seek to do is pass the first test...then others....

Sometimes it can be very useful to write the tests first, as it forces one to think about the API and what the output should ideally look like.

Can't use string ("abcdef") as an ARRAY ref while "strict refs" in use at ./3.rm.pl line 59.

getsubset expects an array of arrays, but $out is just an array of strings. Assuming you want each character to be a "column", you could do $out = [ map { [split //] } @$out ]; after $out = make_rectangular(..., or you integrate it directly in the push in your make_rectangular like so: push @out, [ split //, sprintf "%-*s", $maxlength, $trimmed ]; - either of those changes make your test pass. (Note you should call done_testing; after your tests.)

Replies are listed 'Best First'.
Re^4: rectangularizing input to become array
by Aldebaran (Curate) on Mar 02, 2019 at 23:12 UTC

    Again I'm gonna try to keep my response short vertically by putting the bulk of it in readmore tags. If you like this tack, hey, throw a hermit an upvote.

    This indicates a lot of successes, including my subroutines for printing 2-d arrays being vindicated as not being broken. On github here: sscce

    I think this is an elegant solution. Thank you for your generous comments.

      you could add it to your PATH
      I did all this, but what has it availed me?
      $ ./5.sscce.pl bash: ./5.sscce.pl: No such file or directory

      Note that ./script.pl tells the shell to only look in the current directory. If you run a shell command without the ./ or any other path name, the shell will look in your PATH for a file by that name and run it (it needs to have executable permissions).

      use lib "lib"; ... I don't completely understand how and why people use it.

      Once you've added the script to your PATH and are able to call it from any directory, relative paths used to load libraries will no longer work. That's what my FindBin example does: it'll locate the directory where the script is, no matter what the current working directory is, and then use the lib directory relative to the script's location, not the current working directory.

Re^4: rectangularizing input to become array
by Aldebaran (Curate) on Mar 01, 2019 at 00:27 UTC

    I believe this has passed its first test. Output, then source, just one code tag, buyer beware:

    (Note you should call done_testing; after your tests.)

    Copy that, so, yahoo, right? I'll write a few more tests....