http://www.perlmonks.org?node_id=1107442

AnaximanderThales has asked for the wisdom of the Perl Monks concerning the following question:

Perhaps I'm breaking Perl6::Form through incorrect usage. I'm still learning programming in general, and Perl specifically. At this point I believe I'm just misinterpretting that that what I'm trying to do is actually appropriate to do with Perl6::Form.

First, I chose to use Perl6::Form because I have the ability to set the columns that I'm attempting to fit the information into. I could find no way to do that with 'format.' Additionally, one PerlMonks item I've read, Form is a much easier implementation that builds off of format.

Enough schmoozing -- on to the issues.

I have this code:

# Test Perl6::Form -- submitting code for Perl Monks # zero-padded fields appears to be broken # Declarative width fields appears to calculate the field length # incorrectly use strict; use warnings; use diagnostics; use Perl6::Form; my $columns = 44; my $fID = "TEST"; my $tID = "003 "; my $space = " "; my $fPer = "Test"; my $tPer = "100.0"; my $fVal = "Int for Zero Pad"; my $tVal = "3"; my $fFlo = "Float for Zero Pad"; my $tFlo = 3.2; # Produces error for invalid field length print "Length = " . length($tID) . "\n"; print form { page => { width => ($columns + 1), } }, "{<<{15}<<}|{>(5)>}|{><}|{<<{15}<<}|{>(5)>}%|", $fID, $tID, $space, $fPer, $tPer; # When above is commented out print form is commented out # Produces Use of uninitialized value $whole in pattern match (m//) print form { page => { width => ($columns + 1), } }, "{<<{20}<<}{0>>>>>}", $fVal, $tVal, "{<<{20}<<}{0>>>.>>0}", $fFlo, $tFlo;

I'm not actually interested in using the first 'print form' section (invalid field length), but in trying to make it work correctly, I tried it out. When I have that uncommented and manually format the text to what I want, I receive this error:

Length = 5 Uncaught exception from user code: Inconsistent width for field 2. Specified as '{>(5)>}' but actual width is 7 in call to &form at test_perl6Form.pl line 33. Perl6::Form::fatal("Inconsistent width for field 2.\x{a}", "Specif +ied as '{>(5)>}' but actual width is 7") called at /usr/local/share/p +erl/5.20.1/Perl6/Form.pm line 663 Perl6::Form::segment("{<<{15}<<}|{>(5)>}|{><}|{<<{15}<<}|{>(5)>}%| +\x{a}", ARRAY(0x1e676b8), HASH(0x1e5d400), 0, HASH(0x1e5d448)) called + at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 1097 Perl6::Form::form(undef, undef, "TEST", "003 ", " ", "Test", 100. +0) called at test_perl6Form.pl line 33

In running the code, the length is actually 5. Not sure why it registers +2, but it seems consistent to add 2 extra positions in the length.

The MAIN issue occurs off the second 'print form.' Form breaks when attempting to zero-pad the field. After commenting out the manual padding sections (# Due to bug ... # Begin formatting based on columns), when I run the script I get:

Use of uninitialized value $whole in pattern match (m//) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 340 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl will try to tell y +ou the name of the variable (if any) that was undefined. In some cas +es it cannot do this, so it also tells you what operation you used th +e undefined value in. Note, however, that perl optimizes your progr +am and the operation displayed in the warning may not necessarily app +ear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program. Use of uninitialized value $places in pattern match (m//) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 341 (#1) Use of uninitialized value $whole in pattern match (m//) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 342 (#1) Use of uninitialized value $whole in repeat (x) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 359 (#1) Use of uninitialized value $point in concatenation (.) or string at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 359 (#1) Use of uninitialized value $places in repeat (x) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 359 (#1) Use of uninitialized value $whole in repeat (x) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 360 (#1) Use of uninitialized value $point in concatenation (.) or string at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 360 (#1) Use of uninitialized value $places in repeat (x) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 360 (#1) Use of uninitialized value $point in string ne at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 369 (#1) Use of uninitialized value $whole in numeric gt (>) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 399 (#1) Use of uninitialized value $w in concatenation (.) or string at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 403 (#1) Use of uninitialized value $p in concatenation (.) or string at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 403 (#1) Use of uninitialized value $point in concatenation (.) or string at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 412 (#1) Use of uninitialized value $whole in subtraction (-) at /usr/local/share/perl/5.20.1/Perl6/Form.pm line 413 (#1)
Int for Zero Pad Float for Zero Pad .
So -- the question is: am I breaking Perl6::Form by using it incorrectly? Should I be filing a bug report? Or am I just doing it wrong?