Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A significant part of your formatting code is hidden in <code>pad2str</code>. The problem seems to be how you handle 22 columns with 26 field definitions. My guess is that it is not handling the four non-existent columns at the end. </p> <p>In the particular case you gave, your fields add up to a length of 254. However, you seem to be adding <em>both</em> a 2-character <code>$tblnr</code> value at the beginning <em>and</em> <code>'--'</code> at the end! So do you need 256 or 256 + 2 ('--') for record length? </p> <p>Also in a given length of the large while loop, <code>@AoA[0][1]</code> is <em>constant</em>, why are you evaluating it 26<code>x</code>5 times? That's bad code in PHP or Perl. </p> <ul> <li>Fix pad2str (which you probably don't even need.)</li> <li>Decide whether you want <code>$tblnr</code> at the beginning or '--' at the end--or decide what your record length should be.</li> <li><p>And regard the code transformation below:</p> <pre><code>use List::MoreUtils qw&lt;pairwise&gt;; # push behavior into statement handles... { package DBI::st; sub get_rows { my $sth = shift; my @results; $sth-&gt;execute( @_ ); while ( my @row = $sth-&gt;fetchrow_array ) { push @results, \@row; } $sth-&gt;close; return @results; } } my %needs_adjustment = qw&lt;F0101 1 F6115 1&gt;; $expsel-&gt;bind_columns( \$tabelnaam, \$huidige, \$id); while( $expsel-&gt;fetch()) { $tbl = substr( $tabelnaam, 0, 4 ); $tblnr = substr( $tabelnaam, 2, 2 ); my ( $first_col ) = @AoA = $dbh-&gt;prepare( qq/ SELECT * FROM tblExportspecificatie WHERE tabelnaam = '$tbl' ORDER BY id / )-&gt;get_rows ; my $adjust_first = $needs_adjustment{ $first_col-&gt;[1] }; $first_col-&gt;[2] = 8 if $adjust_first; ( $sth = $dba-&gt;prepare("SELECT * FROM $tbl LIMIT 5"))-&gt;execute; while ( my $row = $sth-&gt;fetchrow_arrayref ) { print $fh $tblnr , ( $adjust_first ? pad2str( 4, 0, $gemeentecode ) : '' ) , ( pairwise { pad2str( @$a[2,3], $b ) } @AoA, @$row ) , chr(10) ; } print $fh chr(10); } </code></pre></li> <li><p>You <em>don't</em> want <code>printf</code>, unless you're going to supply a <em>format specifier</em>--which you do not seem to do.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload