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);

In reply to Re: Re: Re: Lost contents of arrays... by Anonymous Monk
in thread Lost contents of arrays... by fiddler42

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.