Seems to me that your approach is very inefficient. If I understand the OP code, you are extracting patterns to search for from a "labels" file, and then, for each pattern in a given language (english or hindi), you are trying to get all the lines from a particular file that contain the pattern.

But you're reading the latter files again and again for each search pattern, whereas you shouldn't need to read them more than once. The code you posted would probably work (if there were no problems with "magic" characters in the regex patterns), but if "en_1000" or "HI_1000" happen to contain lines where two or more patterns match, those lines get printed multiple times. Is that your intention?

If so, the following should do the same thing (and I think it will go quicker):

#!/usr/bin/perl use strict; use warnings; open( LABELS, "labels" ) or die "labels: $!\n"; my @english; my @hindi; while (<LABELS>) { my ( $eng_indx, $hin_indx ) = map { s/:/|/; $_ } split( /\|/ ); push @english, $eng_indx; push @hindi, $hin_indx; } open( EN, "/home/vikash/pro_1/en_1000" ) or die "en_1000: $!\n"; my @enlines = <EN>; open( HI, "/home/vikash/pro_1/HI_1000" ) or die "HI_1000: $!\n"; my @hilines = <HI>; for my $i ( 0 .. $#english ) { print grep /$english[$i]/, @enlines; print grep /$hindi[$i]/, @hilines; print '*' x 50, "\n"; }
(not tested)

Instead of splitting the English and Hindi "labels" strings on ":", this converts the ":" to "|", so that each label string becomes a single regex with alternations. Then, the "*_1000" files are read only once into memory (this will be a problem if the files are too big).


In reply to Re: shell commands doesn't integrate with perl by graff
in thread shell commands doesn't integrate with perl by vikashiiitdm

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.