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:
Or, if there's a lib subdirectory, using the following (platform-independent) code:use FindBin; use lib $FindBin::Bin;
use FindBin; use File::Spec::Functions qw/catdir/; use lib catdir($FindBin::Bin, 'lib');
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 trimI 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.)
In reply to Re^3: rectangularizing input to become array
by haukex
in thread rectangularizing input to become array
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |