#!/usr/local/bin/perl use feature say; use utf8; use feature qw/switch/; open(my $file,$ARGV[0]) or die("could not open file"); $keep = 1; # Add two because need to read more digits for rounding. $keep += 2; $throw = 5 - $keep; <$file>; while (<$file>) { $_ =~ /^.{8}\s+([0-9]{4})\s+([0-9]{5})\.([0-9]{$keep})[0-9]{$throw}(.*)/; $Ī» = $1; $tš“ƒ = $2; # characteristic $tšœ€ = $3; # mantissa $vals = $4; if ($tšœ€ =~ /([0-9])([0-9])([0-9])/) { $tšœ€ = $1; given($2) { when (/[6-8]/) { $tšœ€ += 1; } when (/5/) { $tšœ€ += 1 if (!($2 == 0)); } } if ($tšœ€ > 9) { $tš“ƒ += 1; $tšœ€ = 0; } # For rounding when even rules #say $2 % 2; #if (!($2%2 == 0) ) { # $tšœ€ = $tšœ€ + 1; #} } else { die "Malformed data encountered"; } say "$Ī»\t$tš“ƒ.$tšœ€$vals"; } close($file);