
BillKSmith
Veteran
Oct 19, 2017, 1:36 PM
Post #5 of 8
(21937 views)
|
Re: [marky9074] Extract from text file, basic trig functions, then graph
[In reply to]
|
Can't Post
|
|
Save the required data in a hash-of-arrays.
C:\Users\Bill\forums\guru>type marky9074.pl use strict; use warnings; use List::MoreUtils qw( any ); use Data::Dumper; my @required_ids = ('R 1', 'R 564', 'R 565', 'R1128', 'R1129'); open my $POS, '<', 'sample3.txt'; my %data; while (<$POS>) { my ($prefix, $id0, $e0, $n0, $id1, $e1, $n1, $id2, $e2, $n2) = unpack 'A (A4xA8A9x4)2 A4xA8A9', $_; $id0 = $prefix.$id0; if (any {$id0 eq $_} @required_ids) { push @{$data{$id0}}, [$e0, $n0]; } $id1 = $prefix.$id1; if (any {$id1 eq $_} @required_ids) { push @{$data{$id1}}, [$e1, $n1]; } $id2 = $prefix.$id2; if (any {$id2 eq $_} @required_ids) { push @{$data{$id2}}, [$e2, $n2]; } } print Dumper(\%data) C:\Users\Bill\forums\guru>perl marky9074.pl $VAR1 = { 'R1129' => [ [ '453507.3', '7998412.9' ], [ '453513.7', '7998408.6' ], [ '453520.7', '7998404.1' ] ], 'R1128' => [ [ '447767.3', '8002471.8' ], [ '447773.2', '8002466.7' ], [ '447779.8', '8002461.3' ] ], 'R 565' => [ [ '453478.2', '7998372.2' ], [ '453484.6', '7998367.9' ], [ '453491.7', '7998363.3' ] ], 'R 1' => [ [ '453448.0', '7998331.8' ], [ '453454.4', '7998327.5' ], [ '453461.6', '7998322.9' ] ], 'R 564' => [ [ '447738.7', '8002432.1' ], [ '447744.7', '8002427.0' ], [ '447751.3', '8002421.5' ] ] }; C:\Users\Bill\forums\guru> Good Luck, Bill
|