in reply to Re: Re: Lost contents of arrays...
in thread Lost contents of arrays...

All,

Thanks so much for all the help--I now have everything working! I needed some extra hand-holding for this one because a lot of the suggestions provided to me were a little (okay, some a lot :-) outside of my perl vocabulary.

Here's a final description of the problem, with working code to follow (below).

Thanks again to all.

Regards,
-Chris

The problem: sort a large file of text formatted like so:

Clock: fci_rx_clk Pin: clkgate_i/peaz_gate7/S_5/Y Net: fci_rx_clk Operating Condition = worst The clock global skew = 0.290 The longest path delay = 4.328 The shortest path delay = 4.038 The longest path delay end pin: co_8port_i\/peaz_i/LOCKUP4/GN The shortest path delay end pin: co_8port_i\/peaz_i/fci_i/dec_i\/bmcf_ +INST\/slice03_INST\/b_reg[5]/CK Clock: aai_tx_clk Pin: clkgate_i/peaz_gate1/S_5/Y Net: aai_tx_clk Operating Condition = worst The clock global skew = 0.192 The longest path delay = 3.430 The shortest path delay = 3.237 The longest path delay end pin: co_8port_i\/peaz_i/aai_i/aai_test_2_a +ai_tx_clk_sgb_2_inst/ff1/CK The shortest path delay end pin: co_8port_i\/peaz_i/aai_i/aai_test_2_a +ai_tx_clk_sgb_0_inst/ff1/CK Clock: aai_rx_clk Pin: clkgate_i/peaz_gate2/S_5/Y Net: aai_rx_clk Operating Condition = worst The clock global skew = 0.349 The longest path delay = 3.996 The shortest path delay = 3.647 The longest path delay end pin: co_8port_i\/peaz_i/LOCKUP/GN The shortest path delay end pin: co_8port_i\/peaz_i/aai_i/atm_path_i\/ +rx_path_i\/rxpram_reg_i\/ar_hec_cnt_reg[3]/CK

...by the "skew" value for each clock. The end result should display all the text in the same format--e.g. 9 lines for each clock--only in a new order. Here is the code to accomplish that...

open (SUM2,">$ARGV[0].sum.sorted"); my @records; { local $/ = /\n\n/; open IN2, "$ARGV[0].sum" or die "Cannot open data file.\n$!"; while ( my $record = <IN2> ) { my @kv_pairs = split /\n/, $record; push @records, [@kv_pairs]; } close IN2; } print STDERR 'Record count: ', scalar @records; my @sorted_recs = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, (split /=\s+/,$_->[4])[1] ] } @records; foreach my $records ( @sorted_recs ) { foreach my $record ( @{$records} ) { print SUM2 $record; } print SUM2 "\n"; } close (IN2); close (SUM2);