Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: While Loops

by kennethk (Abbot)
on Jan 08, 2013 at 18:53 UTC ( #1012311=note: print w/replies, xml ) Need Help??


in reply to While Loops

Your spec is a little ambiguous to me, but if I follow, you can do what you need using Slices and %, perhaps like:
for my $i (0 .. @data/100) { my $max = $i * 100 + 99; $max = @data - 1 if $max > @data - 1; print @data[$i * 100 .. $max]; }

Of course, you'd presumably want to do something between those prints.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: While Loops
by tbone654 (Beadle) on Jan 08, 2013 at 19:07 UTC

    How about something like this?

    foreach $a (0..@data-1) { print or do something ; } ## end of foreach

    If you have the length of the array it knows then when to stop.

      1. You should not use $a as your index variable, or really ever as a generic variable. $a and $b have special meaning for sort.
      2. I'm unclear on how your strategy splits the array into chunks of 100 records. There are certainly a myriad of ways to get this done, but it's not obvious to me how this is one of them.

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012311]
help
Chatterbox?
[choroba]: I want to present the most bizzare bugs and misfeatures I met when working for a large financial institution
[choroba]: I already gave a similar talk to my friends in a pub and at an internal conference at work and people liked it, so maybe...
[choroba]: LanX: That's the heritage, I can't do anything else
[RonW]: Sounds like some system my employer has "It does exactly what we need it to do and can't afford to risk anything we can't prove is 100% compatible"
[marto]: choroba sounds interesting
[RonW]: james28909 Why not write a Perl program to do the task?
[choroba]: RonW Yes, but then, one day, they needed to switch from FTP to SFTP, and... but I can't give the whole talk away here :)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-05-22 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?