Perhaps the word you are missing is 'magnitude'.
Try this:
#! perl -slw use strict; sub log10{ log( $_[0] ) / log( 10 ) } sub magnitude{ int log10( $_[0] ) } sub sign { $_[0] <=> 0 } my @nums = sort{ $b <=> $a } qw[ 1.3e-3 3.7e-5 102 46 1e-4 1e-12 ]; my @byMag; my $prev = $nums[ 0 ]; for my $i ( 1 .. $#nums ) { my $this = $nums[ $i ]; my $diff = abs( magnitude( $prev ) - magnitude( $this ) ); --$diff if sign( magnitude( $this ) ) == sign( magnitude( $prev ) +); push @byMag, $prev; push @byMag, ( 0 ) x $diff if $diff > 1; $prev = $this; } push @byMag, $prev; print for @byMag; __END__ C:\test>1054890.pl 102 46 0 0 0 1.3e-3 1e-4 3.7e-5 0 0 0 0 0 0 1e-12
In reply to Re: place floats into array (Corrected.)
by BrowserUk
in thread place floats into array
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |