Hello everyone,

If I have a file in which I am searching for any line beginning with "Open Square Bracket" and ending with "Close Square Bracket" and then saving all such matching lines in an Array called @BROKERS. How would I tell perl to go through the file again, matching on each element of @Brokers, and then after it found a line that matched that element push each subsidiary line that followed into an array named $BROKER[x] until a blank line is reached. At this point the loop should continue to the next element of @BROKERS and repeat the above proccess until there are no elements left.

I am very new to perl and languages in general so please excusive the crudity of the code I have written so far.

#!/usr/bin/perl -w # my @BROKERS; open (CONFIG, "ubroker.properties") || die "Can't Open ubroker file: $ +!"; while (<CONFIG>) { next if /^#/; if (/^\[UBroker\.WS\./) { push (@BROKERS,$_); } } chomp @BROKERS; while (<CONFIG>) { foreach $b(@BROKERS) { if (/$b/) { # Here is where I run out of steam # Begin Metacode read each line and push ($_,@"$b") continue to do this until + a newline is reached. When a newline is reached intialize the next +$b as an array and repeat the above proccess until all elements of @B +ROKERS are exhausted.

I hope the question ain't to crude, if it is I'll be glad to expand on it!
Thanks!
Pat

Edit by tye


In reply to 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.