This snippet makes a few assumptions and glosses over a few implementation details:

Given those assumptions the following snippet will parse the file and place each "module/id" pair into an anonymous array, with all of them pushed onto an array poorly named @results.

use strict; use warnings; use autodie; my $filename = 'something.doc'; my @results; open my $in_fh, '<', $filename; my( $module, $id ); while( my $line = <$in_fh> ) { chomp $line; if( $line =~ /^Module:\s+(\d+)/ ) { $module = $1; next; } if( $line =~ /^ID:(\d+)/ ) { $id = $1; next; } if( $line =~ /yes/ ) { push @results, [ $id, $module ]; } }

It may feel unclean allowing $module and $id to retain values from one iteration to the next, even after a 'no' in the 'Customer:' field. But as long as the input is well formed, $module and $id will always contain valid information at the moment a 'yes' is encountered.


Dave


In reply to Re: Need Help in Array by davido
in thread Need Help in Array by rajkrishna89

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.