hi,

I have two files.

file1
------
12131
34234
53435
46566
34522

file2
------
some content
some content
some content
some content
some content
blah. blah.
Code id -46566-
some content
some content
some content
some content
Event id -445778441211-
some content
some content
some content
some content
some content
some content
some content
Code id -12131-
some content
some content
some content
some content
some content
some content
some content
some content
some content
Event id -123443111131-
Code id -12342-
some content
some content
some content
some content
some content
some content
some content
some content
Event id -445987432141-

file1 contains the list of codes, and file2 contains, code with its id and after some lines corresponding event ids for that code id.

My output should have list of code ids and its corresponding event id.

I have written the following code to achieve the above requirement

use strict; use warnings; open (FH1, "file1"); open (FH2, "file2"); my ($code, $event, $line); my %data; while (<FH1>) { chomp; # assigning code. $code = $_; while ( <FH2> ) { chomp; if ( $_ =~ /\-$code\-/ ) { $line = $_; while ( $line !~ /Event id (.*)/ ) { $line = <FH2>; chomp; } if ( $line =~ /Event id (.*)/ ) { $data{$code} = $1; } } } seek(FH2,0,0); } print "OUTPUT"; print %data;

It works, but i want some other way which should be simple and effective.


In reply to parsing with two files by perlthirst

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.