So back to the question. How can I nest this foreach loop correctly to add all 
occurrences of the element rlptxat that have the same elements cell, sect and 
chan in the array?

$record{rlptxat} = ( length($record{rlptxat})> 1 ) ? $record{rlptxat}{cell, 
sect, chan, dist}++ : '' ;

Thank you very much.

Chris

#!/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,
        rlptxat => 44,
);

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{rlptxat} = ( length($record{rlptxat})> 1 ) ? 
$record{rlptxat}{cell, sect, chan, dist}++ : '' ;
        
####################################################################
        
        $record{carr} =
                ( $record{chan} == 75 )   ? 2 :
                ( $record{chan} == 1025 ) ? 2 : 1 ;
                                                                        #1; # 
Common carrier
        $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}\t$_->{sect}\t$_->{carr}\t$_->{chan}\t$_->{dist}\n" 
, @sorted;



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