use strict;
use warnings;
foreach (3.5, 2.6888, 8.25 ,8, 1249.7999999999999999)
{
printf("%.3f\n", $_);
}
__END__
3.500
2.689 note <= rounding up from 2.6888
8.250
8.000
1249.800 <= note rounded up from 7999999999999
####
use strict;
use warnings;
while (my $line = )
{
if ($line =~ m/^UFRAME/)
{
my @numbers = $line =~ /([\d.]+)/g;
print "UFRAME numbers: @numbers\n";
@numbers = map{sprintf "%.3f",$_}@numbers;
print "UFRAME numbers with 3 decimal points: @numbers\n\n";
}
}
=prints:
UFRAME numbers: 3.0 5.6 7.9000999 43.08999
UFRAME numbers with 3 decimal points: 3.000 5.600 7.900 43.090
UFRAME numbers: 2.57777 32.000 54 1
UFRAME numbers with 3 decimal points: 2.578 32.000 54.000 1.000
=cut
__DATA__
nonsense
UFRAME 3.0, 5.6, 7.9000999, 43.08999
BS
UFRAME 2.57777, 32.000,54,1
####
#!/usr/bin/perl
use strict;
use warnings;
#data format
#UFRAME,index,number,x,y,z
while (my $line =)
{
next unless $line =~ /UFRAME/;
chomp $line;
my (undef,$index,$number,@coordinates) = split /,/,$line;
print "Index=$index, Number=$number, Coordinates =@coordinates\n";
warn_coordinate_zero(@coordinates);
}
sub warn_coordinate_zero
{
my (@corrdinates)= @_;
print " X value is not zero\n" if (shift @corrdinates);
print " Y value is not zero\n" if (shift @corrdinates);
print " Z value is not zero\n" if (shift @corrdinates);
}
=Prints
Index=32, Number=14, Coordinates =0 0 0
Index=32, Number=99, Coordinates =0 0 45
Z value is not zero
Index=32, Number=959, Coordinates =65 0 0
X value is not zero
Index=32, Number=959, Coordinates =99 0 23
X value is not zero
Z value is not zero
=cut
__DATA__
UFRAME,32,14,0,0,0
BOGUS
UFRAME,32,99,0,0,45
UFRAME,32,959,65,0,0
UFRAME,32,959,99,0,23