This queue is for tickets about the Perl6-Form CPAN distribution.

Report information
The Basics
Id:
100413
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
chris [...] cuberootent.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: Issues with Declarative Widh and Zero-Paddidng fields
Date: Mon, 17 Nov 2014 19:26:59 -0600
To: bug-Perl6-Form@rt.cpan.org
From: Christopher Pearson <chris@cuberootent.com>
Perl6::Form

Perl v5.20.1 on Linux 3.16.0-25-generic #33-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux

The code produces the corresponding included errors.

Not sure if I'm doing something wrong, or if something get off or if I'm missing just breaking it through incorrect use.

==============================================

# 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;



# Produces Unintialized value $whole in patter match (m//) error
  print form  { page => { width  => ($columns + 1), } },
    "{<<{20}<<}{0>>>>>}", 
    $fVal, $tVal,
    "{<<{20}<<}{0>>>.>>0}", 
    $fFlo, $tFlo;

==============================================

Invalid field length 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}", "Specified as '{>(5)>}' but actual width is 7") called at /usr/local/share/perl/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

==============================================

Unintialized value $whole in patter match (m//) error:
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 already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.
    
    To help you figure out what was undefined, perl will try to tell you
    the name of the variable (if any) that was undefined.  In some cases
    it cannot do this, so it also tells you what operation you used the
    undefined value in.  Note, however, that perl optimizes your program
    and the operation displayed in the warning may not necessarily appear
    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       .

Subject: Re: [rt.cpan.org #100413] Issues with Declarative Widh and Zero-Paddidng fields
Date: Tue, 18 Nov 2014 13:03:52 +1100
To: bug-Perl6-Form@rt.cpan.org
From: Damian Conway <damian@conway.org>
Hi Chris, These are not bugs, just incorrect usages. In the first call to form(), the format:
Show quoted text
> "{<<{15}<<}|{>(5)>}|{><}|{<<{15}<<}|{>(5)>}%|",
...is invalid. A number in parens within a field is a checksum, and specifies that the field must physically be the same number of characters wide as the number specifies. So {>(5)>} is an error, because it specifies a required width of 5, but the field itself is actually 7 characters wide. You probably want a declarative width specifier like: {>{5}>} instead (a braced number inside a field specifies how wide the field should be treated as, regardless of its actual physical width). In the second call to form(), the format:
Show quoted text
> "{<<{20}<<}{0>>>>>}",
...is also invalid. Declarative in-field zero padding only applies to numeric fields (i.e. fields of the form {0>>>.<<}). Furthermore, the second format:
Show quoted text
> "{<<{20}<<}{0>>>.>>0}",
...is invalid too. Its second field is not a valid numeric field specifier, which must have both sets of arrows pointing towards the decimal point. So what you needed was: print form { page => { width => ($columns + 1), } }, "{<<{20}<<}{>>>>>}", $fVal, {lfill=>0},$tVal, # Specify $tVal to be left-filled with 0's "{<<{20}<<}{0>>>.<<<}", # Specify $tFlo field to be a numeric field $fFlo, $tFlo; I've appended a fully corrected version of your example, which works as I think you would wish. Hope this helps, Damian -----cut----- 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; # Produces Unintialized value $whole in patter match (m//) error print form { page => { width => ($columns + 1), } }, "{<<{20}<<}{>>>>>}", $fVal, {lfill=>0},$tVal, "{<<{20}<<}{0>>>.<<0}", $fFlo, $tFlo;
Subject: Re: [rt.cpan.org #100413] Issues with Declarative Widh and Zero-Paddidng fields
Date: Mon, 17 Nov 2014 20:34:45 -0600
To: bug-Perl6-Form@rt.cpan.org
From: Christopher <chris@cuberootent.com>
Damian,

Thank you, it's particularly helpful with what I was hoping to use.  However, I'm not sure the declarative part is exactly addressed.  The length give by perl shows that the field is actually 5 positions.  That's why I was wondering about it.  It seems that {>(5)>} should work if my value is registering from perl as 5 characters.  Instead, form is calling it 7 characters.  I'm fully satisfied that the issue is resolved, but now I'm curious as to why perl would say $tID is length 5 but form would say $tID is length 7.

My real issue was with the zero-padding, so I'm satisfied with the fact that I just wasn't paying close enough attention.

Thank you,
Christopher

On Mon, Nov 17, 2014 at 8:04 PM, damian@conway.org via RT <bug-Perl6-Form@rt.cpan.org> wrote:
Show quoted text
<URL: https://rt.cpan.org/Ticket/Display.html?id=100413 >

Hi Chris,

These are not bugs, just incorrect usages.

In the first call to form(), the format:

>     "{<<{15}<<}|{>(5)>}|{><}|{<<{15}<<}|{>(5)>}%|",

...is invalid. A number in parens within a field is a checksum, and
specifies that the field must physically be the same number of
characters wide as the number specifies. So {>(5)>} is an error, because
it specifies a required width of 5, but the field itself is actually 7
characters wide. You probably want a declarative width specifier like:
{>{5}>} instead (a braced number inside a field specifies how wide the
field should be treated as, regardless of its actual physical width).

In the second call to form(), the format:

>     "{<<{20}<<}{0>>>>>}",

...is also invalid. Declarative in-field zero padding only applies to
numeric fields (i.e. fields of the form {0>>>.<<}).

Furthermore, the second format:

>     "{<<{20}<<}{0>>>.>>0}",

...is invalid too. Its second field is not a valid numeric field specifier,
which must have both sets of arrows pointing towards the decimal point.

So what you needed was:

  print form  { page => { width  => ($columns + 1), } },
    "{<<{20}<<}{>>>>>}",
     $fVal,    {lfill=>0},$tVal,     # Specify $tVal to be left-filled with 0's
    "{<<{20}<<}{0>>>.<<<}",   # Specify $tFlo field to be a numeric field
     $fFlo,   $tFlo;

I've appended a fully corrected version of your example, which works as
I think you would wish.

Hope this helps,

Damian

-----cut-----

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;



# Produces Unintialized value $whole in patter match (m//) error
  print form  { page => { width  => ($columns + 1), } },
    "{<<{20}<<}{>>>>>}",
    $fVal, {lfill=>0},$tVal,
    "{<<{20}<<}{0>>>.<<0}",
    $fFlo, $tFlo;


Subject: Re: [rt.cpan.org #100413] Issues with Declarative Widh and Zero-Paddidng fields
Date: Tue, 18 Nov 2014 14:59:43 +1100
To: bug-Perl6-Form@rt.cpan.org
From: Damian Conway <damian@conway.org>
Chris,
Show quoted text
> The length give by perl shows that the field is actually 5 positions.
No. The length of the *data* for the field is 5. :-) The *field* is the specification "{>(5)>}", which is definitely 7 characters in width (and hence invalid, since the "(5)" specifies that the surrounding field must be 5 characters wide. In other words, declarative field widths are not about validating the data to be interpolated; they are about checking that the field specification itself is consistent. In practice, declarative field widths are mostly only used for formats that have been autogenerated, as a way of checking that the field you somehow constructed is the correct width. They are not in any way about verifying the data to be formatted into a field. In fact, form() has no features for validating the data it formats. It just does its best to accommodate whatever data you through at it.
Show quoted text
> I'm curious as to why perl would say $tID is length 5 but form would say > $tID is length 7.
That's the misunderstanding in a nutshell. form() isn't saying the contents of $tID is of length 7; it's saying that the specifier for the "{>(5)>}" field into which $tID is being formatted is of length 7. All the best, Damian
Subject: Re: [rt.cpan.org #100413] Issues with Declarative Widh and Zero-Paddidng fields
Date: Tue, 18 Nov 2014 07:23:26 -0600
To: bug-Perl6-Form@rt.cpan.org
From: Christopher <chris@cuberootent.com>
Damian,

Thanks for the explanation -- I'll have to wrap my head around it and hammer on it but I'll eventually comprehend it fully.  I'm still learning, and this is my first foray into using form or predefined formatting of any kind.  And on top of it, I'm still learning programming.

I appreciate the time.

Thank you,
Christopher

On Mon, Nov 17, 2014 at 10:00 PM, damian@conway.org via RT <bug-Perl6-Form@rt.cpan.org> wrote:
Show quoted text
<URL: https://rt.cpan.org/Ticket/Display.html?id=100413 >

Chris,

> The length give by perl shows that the field is actually 5 positions.

No. The length of the *data* for the field is 5. :-)

The *field* is the specification "{>(5)>}", which is definitely 7
characters in width (and hence invalid, since the "(5)" specifies that
the surrounding field must be 5 characters wide.

In other words, declarative field widths are not about validating the data
to be interpolated; they are about checking that the field specification itself
is consistent. In practice, declarative field widths are mostly only used
for formats that have been autogenerated, as a way of checking that the
field you somehow constructed is the correct width. They are not in any
way about verifying the data to be formatted into a field.

In fact, form() has no features for validating the data it formats.
It just does its best to accommodate whatever data you through at it.


> I'm curious as to why perl would say $tID is length 5 but form would say
> $tID is length 7.

That's the misunderstanding in a nutshell. form() isn't saying the contents of
$tID is of length 7; it's saying that the specifier for the "{>(5)>}"
field into which
$tID is being formatted is of length 7.

All the best,

Damian




This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.