You would probably be best to use a hash where the key is the broker you find and the values is the data. Here is an example:

#!/usr/bin/perl -w use strict; my (%brokers, $broker); # get file contents into an array for convenience open (CONFIG, "ubroker.properties") || die "Can't Open ubroker file: $ +!"; while (<CONFIG>) { next if /^#/; chomp; $broker = $_ if /^\[.*\]$/; # found a broker $broker = '' if /^\s*$/; # found a blank line # add line to current $broker if there is one $brokers{$broker} .= "$_\n" if $broker; } close CONFIG; # keys %brokers returns an array of brokers to iterate over for (keys %brokers) { print "\nBroker: $_\n"; # this is the broker name print $brokers{$_}; # this is the data (includes name) }

If you want to do it with a while(<CONFIG>) you either need to do it in one loop (as you will reach the end of the file after the first loop) or use seek CONFIG, 0, 0; to go back to the begining of the file before you do a second while loop through it.

In this example we use a hash to store both the brokers array (as the keys) and the data associated with each broker (as the values) which means that there is a logical link between the data. If you just wanted arrays then:

@brokers = keys %brokers; @data = values %brokers;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Appropriate application of readline by tachyon
in thread Appropriate application of readline by quasimojo

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.