in reply to Parsing Form Input

substr can help with carving up a string, and if you use it coupled with an array, you could easily tell how many chunks you split the string into by seeing how big the array is...

my @chunks; while ( 1 ) { my $chunk = substr( $initial, 0, 100, "" ); last unless length $chunk; # was it empty? push @chunks, $chunk; } print scalar(@chunks), " chunks\n";

    --k.


Replies are listed 'Best First'.
Re: Re: Parsing Form Input
by particle (Vicar) on Apr 22, 2002 at 12:18 UTC
    you can simplify that loop by:
    sub LIMIT () { 100 } my @chunk; while( my $chunk = substr( $initial, 0, LIMIT, '') ) { push @chunks, $chunk; }
    actually i threw a constant in there as well. it won't simplify the loop, but it should ease maintenance.

    ~Particle ;Þ