Monks, I have code which generates a large XML packet (containing hundreds of packet_refs, see below) based on the result of a SQL query. I want to break this down so that 1 XML packet, each containing 10 packet_ref's is sent, then looped for the rest of the results. I've tried to adapt my code to do this, but I don't know what the condition should be for the if statement. As requested, this is a cut down example of my code. Please advise

foreach my $item (@SQLvars){ my $sth = $self->dbh()->prepare($DocumentQuery) or die "Can't prepair statement: $self->DBI::errstr"; my ( $foo, $bar ); $sth->execute( $item->{PACKID}, $item->{PACKINFO} ); $sth->bind_columns(\( $foo, $bar )); while ($sth->fetch) { $XMLContent .= "<packet_ref> <packID>$foo</packID> <packInfo>$bar</packINFO> </packet_ref>\n"; if (){ # if there are 10 packet_ref's send the XML and loop round + for the remainder my $XMLPacket; $XMLPacket = $XMLHead . $XMLContent . $XMLFoot; my $mech = WWW::Mechanize->new(); $mech->get( $TargetURL ); $mech->field( "xml_doc", $XMLPacket ); my $mechres = $mech->submit(); if ($mechres->is_success) { warn $mechres->decoded_content; return "Success"; }else{ warn $mechres->status_line, "\n"; return "Error"; } undef $XMLContent; } } }

In reply to Dynamically breaking up a data set by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.