Hello,

I would like to explicitly use printf '<%.2g>' for the element in the array 
called dist.
Below is the error I am getting and below that is a sample of the output I can 
currently generate before I add printf.

Thank you

Argument "2,1,1,1175,2.58522727272727,1\n" isn't numeric in printf at 
./DOband1.pl line 47.
<2> 

2,1,1,1175,2.58522727272727,1
2,1,1,1175,,
2,1,1,1175,1.35416666666667,1
2,1,1,1175,1.82765151515152,1
2,1,1,1175,,
2,2,1,1175,,
8,1,1,1175,,
10,2,1,1175,0.710227272727273,1



#!/usr/bin/perl

use warnings;
use strict;
use File::Slurp;

my $filepath = 'C:/temp/PCMD';
my $output  = 'output.txt';

my %cols = (
        cell    => 31,
        sect    => 32,
        chan    => 38,
        dist    => 261,
        precis  => 262,
);

my @records;

my @lines = read_file( $filepath );

chomp @lines;

foreach my $line ( @lines ) {

        next unless $line =~ /;/;
        my %record;
# this gets just what you want into a hash using a hash slice and an # array 
slice. 
# the order of keys and values will be the same for any # given hash

        @record{ keys %cols } = (split /;/, $line)[ values %cols ];
        $record{carr} = ( $record{chan} == 15 ) ? 2 : 1 ;       
        $record{dist} = ( length( $record{dist}) > 1 ) ? 
$record{dist}/6.6/8/2*10/10 : '' ;

        push( @records, \%record ) ;
}

my @sorted = sort {
                $a->{cell} <=> $b->{cell} ||
                $a->{sect} <=> $b->{sect} ||
                $a->{carr} <=> $b->{carr}
        } @records ;

my @report = map 
"$_->{cell},$_->{sect},$_->{carr},$_->{chan},$_->{dist},$_->{precis}\n" , 
@sorted;
#my @report = map "@{$_{ keys %cols }}\n", @records ;

 printf '<%.2g>', @report ;
#print @report ;
write_file($output, @report) ;



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to