Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: how to seperate array after a certain number of elements?

by ikegami (Patriarch)
on Sep 20, 2007 at 19:53 UTC ( [id://640224]=note: print w/replies, xml ) Need Help??


in reply to Re: how to seperate array after a certain number of elements?
in thread how to seperate array after a certain number of elements?

It's dangerous to repeatedly add decimal numbers since many of them are periodic in binary and therefore cannot be stored precisely. This includes 0.2.

>perl -le"printf '%.17f', .2 0.20000000000000001

The following is a safer, simpler and easier to read (since "5" actually appears) version of your second snippet:

use List::MoreUtils qw(part); my @array = (1..100); my $i; my @parts = part { ($i++)/5 } @array;

Replies are listed 'Best First'.
Re^3: how to seperate array after a certain number of elements?
by artist (Parson) on Sep 24, 2007 at 19:12 UTC
    Thanks, I never knew the reason behind it. Very useful tip.
    --Artist

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://640224]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found