vikashiiitdm has asked for the wisdom of the Perl Monks concerning the following question:

i had been doing this. but the $eng_dat and $hindi_dat never get printed. how do i solve this issue.

#!/bin/env perl open(HANDLE,"<labels");@lines=<HANDLE>;close HANDLE; for($i=0;$i<=$#li +nes;$i++) { ($english_index,$hindi_index,$nua)=split(/\|/,$lines[$i]); @english=split(/:/,$english_index); @hindi=split(/:/,$hindi_index); print @english,"\n",@hindi,"\n"; for($j=0;$j<=$#english;$j++) { $eng_dat=`grep --regexp '$english[$j]' /home/vikash/pro_1/en_1000`; print $eng_dat; } for($j=0;$j<=$#hindi;$j++) { $hindi_dat=`grep --regexp '$hindi[$j]' /home/vikash/pro_1/HI_1000`; print $hindi_dat; } print "********************************************************* ***** +*\n"; }

Replies are listed 'Best First'.
Re: shell commands doesn't integrate with perl
by jethro (Monsignor) on Jul 15, 2011 at 12:54 UTC

    First of all you should remove the \n from files you read from disk (perl doesn't remove newlines from files it reads automatically. Because of that it can read binary files with the same commands). Add "chomp(@lines);" after "@lines=<HANDLE>". Maybe this was the problem you had with a lot of your scripts lately

    I assume your grep doesn't find anything. I would suggest two tests. First substitute

    $eng_dat=`grep ...`;

    with

    print "grep ..."

    and observe if the regexp is what you expect

    Then substitute the same line with

    system("echo grep ..."); system("grep ...");

    Now you should see what the shell makes of your command and get the output directly on STDOUT

    Somewhere along these tests you should see a discrepancy. Or your search strings are really not in those files

Re: shell commands doesn't integrate with perl
by bart (Canon) on Jul 15, 2011 at 12:15 UTC
    Any chance of posting a few lines of the data file, so we can actually run something instead of doing it all in our heads?

      i am posting a few lines from the data files and a modified script but the problem am facing is that @ each run of the loop it just scans the whole file and not the single line.

      #!/usr/bin perl open(DAT,">final_result"); open(HANDLE,"<labels"); while($line=<HANDLE>) { chomp($line); ($english_index,$hindi_index,$nua)=split(/\|/,$line); @english=split(/:/,$english_index); @hindi=split(/:/,$hindi_index); for($j=0;$j<=$#english;$j++) { $eng_dat=`grep --regexp '$english{$j}' /home/vikash/pr +o_1/en_1000`; print DAT $eng_dat; } for($j=0;$j<=$#hindi;$j++) { $hindi_dat=`grep --regexp '$hindi{$j}' /home/vikash +/pro_1/HI_1000`; print DAT $hindi_dat; } print DAT "************************************************** +***************\n"; } close DAT; __END__

      the sample labels data file is

      EN-1000-0002-1|HI-1000-0001-1:HI-1000-0002-1| EN-1000-0003-1|HI-1000-0003-1| EN-1000-0003-2|HI-1000-0003-2| EN-1000-0003-3|HI-1000-0003-3| EN-1000-0004-1:EN-1000-0004-2|HI-1000-0004-1| EN-1000-0004-3|HI-1000-0005-1| EN-1000-0005-1|HI-1000-0005-2| EN-1000-0005-2|HI-1000-0005-3| EN-1000-0006-1|HI-1000-0006-1| EN-1000-0006-2:EN-1000-0006-3|HI-1000-0006-2| EN-1000-0008-1|HI-1000-0008-1:HI-1000-0008-2| EN-1000-0008-2:EN-1000-0008-3|HI-1000-0008-3|

      n the sample en_1000 file is

      <p id=EN--1000-0002-1> Nehru Bal Pustakalaya THE COSMIC GIFT Mohan S +undara Rajan Neeta Gangopadhya National Book Trust, India UNDER TH +E SEA An Indian research submarine was exploring the ocean-bed off t +he coast of Parson's Pygmalion Point, the southern-most tip of India. + Its young Captain, Uttama, and his crew gazed entranced at the stran +ge world under water, strangely lit here and there with many-shaped c +oral reefs, amidst which innumerable varieties of colourful fish and +creatures of weird shapes flitted. </p> <p id=EN--1000-0003-1> Then a sharp order came through. All movement m +ust be halted. A naval exercise was planned. </p> <p id=EN--1000-0003-2> The engines were turned off. All was still and +waiting. Suddenly, Uttama spotted a peculiar object lying among the c +oral. It was smooth and of a single unusual colour among the infinite + variety around it. It did not resemble any living creature. Curious. + Uttama ordered it be captured. </p> <p id=EN--1000-0003-3> The object turned out to be a big meteorite. Ut +tama was delighted. He had never seen anything like it on sea or land + before. Despite its journey in space and stay in water, it had retai +ned its shape and colour. </p> <p id=EN--1000-0004-1> The stand-still alert ended. Uttama was ordered + to surface. He immediately telephoned his friend, Professor Maruthi +of the Stellar School in the Kavalur Observatory complex and informed + him about the meteorite. </p> <p id=EN--1000-0004-2> Professor Maruthi was very excited. The meteori +te was the largest he had ever heard of. Receiving permission to exam +ine it Professor Maruthi began conducting tests on the cosmic relic. + </p> <p id=EN--1000-0004-3> As layer after layer of filmy material was remo +ved, a clear pattern emerged, looking like 10101 which Professor Maru +thi suggested was a binary code for 21. And 21 could stand for the 2 +1 cm. radio frequency of hydrogen in space. </p> <p id=EN--1000-0005-1> Was it a message from some intelligent beings i +n outer space? </p> <p id=EN--1000-0005-2> For many years scientists on earth had been sen +ding out messages of coded primary mathematics in the hope of these b +eing picked up but so far there had been no answer. Could this be it? + </p> <p id=EN--1000-0006-1> MESSAGE FROM A METEORITE News of the meteorite + and its binary content were broadcast by all radio stations in the w +orld. Immediately, a furious debate broke out. The Americans announce +d that they would make special spacecraft and set off to explore the +territory from which the outer space beings had sprung. The Russians, + on the other hand, wanted to move cautiously and wait till fuller co +ntact through the binary code was established. </p> <p id=EN--1000-0006-2> There were also telegrams pleading for a halt t +o further communication lest another civilisation assess our technolo +gy as primitive. Others, however, argued that the intentions of any c +ivilisation which could survive so long might not be evil. Contact wi +th it need not prove dangerous and could even be greatly beneficial. + </p> <p id=EN--1000-0006-3> Professor Maruthi went ahead with preparations +to send a message to outer space. He suggested a method to code the m +essage that would be recognised as undoubtedly coming from intelligen +t beings. He said that the message could be sent in a single successi +on of 'On-Off pulses of radiation. The pulses could represent ones a +nd their absence zeros. Thus a binary series of numbers would be tran +smitted. Again, these numbers could be the first twelve primary numbe +rs, viz. 1, 2, 3, 5, 7, 11, 13,17,19, 23, 29 and 31. This would indic +ate simple mathematical knowledge which could only come from intelli +gent beings. There was even a possible method of arranging such a mes +sage to give a clear description. By putting an array of 29 groups of + 19 squares, for example, and by colouring the ones black and zeros w +hite, an interesting picture could be shown, indicating the physical +appearance of human beings, how the solar system functioned and other + important facts. </p>

      the sample hi_1000 file

      <p id=HI--1000-0001-1> 1 &#2309;&#2306;&#2340;&#2352;&#2367;&#2325;&#2 +381;&#2359; &#2325;&#2366; &#2357;&#2352;&#2342;&#2366;&#2344; &#2344 +;&#2375;&#2361;&#2352;&#2369; &#2348;&#2366;&#2354; &#2346;&#2369;&#2 +360;&#2381;&#2340;&#2325;&#2366;&#2354;&#2351; &#2309;&#2306;&# +2340;&#2352;&#2367;&#2325;&#2381;&#2359; &#2325;&#2366; &#2357;&#2352 +;&#2342;&#2366;&#2344; &#2350;&#2379;&#2361;&#2344; &#2360;&#2369; +&#2306;&#2342;&#2352; &#2352;&#2366;&#2332;&#2344; &#2344;&#2368;& +#2340;&#2366; &#2327;&#2306;&#2327;&#2379;&#2346;&#2366;&#2343;&#2381 +;&#2351;&#2366;&#2351; &#2360;&#2369;&#2352;&#2375;&#2358; &#2313; +&#2344;&#2367;&#2351;&#2366;&#2354; &#2344;&#2375;&#2358;&#2344;& +#2354; &#2348;&#2369;&#2325; &#2335;&#2381;&#2352;&#2360;&#2381;&#233 +5;, &#2311;&#2306;&#2337;&#2367;&#2351;&#2366; 2 &#2309;&#2306;&#234 +0;&#2352;&#2367;&#2325;&#2381;&#2359; &#2325;&#2366; &#2357;&#2352;&# +2342;&#2366;&#2344; ISBN 81-237-0945-5 +&#2346;&#2361;&#2354;&#2366; &#2360;&#2306;&#2360;&#2381;&#2325;&#235 +2;&#2339; : 1983 &#2348;&#2366;&#2352;&#2361;&#2357;&#2368;&#2306; +&#2310;&#2357;&#2371;&#2340;&#2381;&#2340;&#2367; : 2001(&#2358;&#232 +5; 1922) &#2350;&#2370;&#2354; &#2350;&#2379;&#2361;&#2344; &#2360; +&#2369;&#2306;&#2342;&#2352; &#2352;&#2366;&#2332;&#2344;, 1983 &#2 +361;&#2367;&#2306;&#2342;&#2368; &#2309;&#2344;&#2369;&#2357;&#2366;& +#2342; &#2344;&#2375;&#2358;&#2344;&#2354; &#2348;&#2369;&#2325; &#23 +35;&#2381;&#2352;&#2360;&#2381;&#2335;, &#2311;&#2306;&#2337;&#2367;& +#2351;&#2366;, 1983 A Comic Gift (Hindi) &#2352;&#2369;0 9.00 & +#2344;&#2367;&#2342;&#2375;&#2358;&#2325;, &#2344;&#2375;&#2358;&#234 +4;&#2354; &#2348;&#2369;&#2325; &#2335;&#2381;&#2352;&#2360;&#2381;&# +2335;, &#2311;&#2306;&#2337;&#2367;&#2351;&#2366;, &#2319;- 5 &#2327; +&#2381;&#2352;&#2368;&#2344; &#2346;&#2366;&#2352;&#2381;&#2325; &# +2344;&#2351;&#2368; &#2342;&#2367;&#2354;&#2381;&#2354;&#2368;- 11001 +6 &#2342;&#2381;&#2357;&#2366;&#2352;&#2366; &#2346;&#2381;&#2352;&#2 +325;&#2366;&#2358;&#2367;&#2340; </p> <p id=HI--1000-0002-1> &#2349;&#2366;&#2352;&#2340; &#2325;&#2375; +&#2342;&#2325;&#2381;&#2359;&#2367;&#2339;&#2368; &#2331;&#2379;&#235 +2; &#2325;&#2375; &#2311;&#2306;&#2342;&#2367;&#2352;&#2366; &#2346;& +#2377;&#2311;&#2306;&#2335; &#2325;&#2375; &#2340;&#2335; &#2360;&#23 +75; &#2354;&#2327;&#2375; &#2361;&#2369;&#2319; &#2360;&#2366;&#2327; +&#2352; &#2340;&#2354; &#2346;&#2352; &#2319;&#2325; &#2349;&#2366;&# +2352;&#2340;&#2368;&#2351; &#2326;&#2379;&#2332;&#2368; &#2346;&#2344 +;&#2337;&#2369;&#2348;&#2381;&#2348;&#2368; &#2326;&#2379;&#2332;&#23 +48;&#2368;&#2344; &#2325;&#2352; &#2352;&#2361;&#2368; &#2341;&#2368; +| &#2325;&#2346;&#2381;&#2340;&#2366;&#2344; &#2313;&#2340;&#2381;&#2 +340;&#2350; &#2324;&#2352; &#2313;&#2360;&#2325;&#2375; &#2342;&#2354 +; &#2325;&#2375; &#2309;&#2344;&#2381;&#2351; &#2354;&#2379;&#2327; & +#2346;&#2366;&#2344;&#2368; &#2325;&#2375; &#2349;&#2368;&#2340;&#235 +2; &#2325;&#2368; &#2313;&#2360; &#2357;&#2367;&#2330;&#2367;&#2340;& +#2381;&#2352; &#2342;&#2369;&#2344;&#2367;&#2351;&#2366; &#2325;&#237 +9; &#2348;&#2337;&#2375; &#2309;&#2330;&#2352;&#2332; &#2360;&#2375; +&#2342;&#2375;&#2326; &#2352;&#2361;&#2375; &#2341;&#2375;| &#2311;&# +2343;&#2352;-&#2313;&#2343;&#2352; &#2325;&#2312; &#2310;&#2325;&#236 +6;&#2352;&#2379;&#2306; &#2350;&#2375;&#2306; &#2350;&#2370;&#2306;&# +2327;&#2379;&#2306; &#2325;&#2368; &#2330;&#2335;&#2335;&#2366;&#2344 +;&#2375;&#2306; &#2330;&#2350;&#2325; &#2352;&#2361;&#2368; &#2341;&# +2368; &#2324;&#2352; &#2313;&#2344;&#2325;&#2375; &#2349;&#2368;&#234 +0;&#2352; &#2325;&#2312; &#2325;&#2367;&#2360;&#2381;&#2350; &#2325;& +#2368;, &#2352;&#2306;&#2327; &#2357;&#2367;&#2352;&#2306;&#2327;&#23 +68; &#2350;&#2331;&#2354;&#2367;&#2351;&#2377; &#2324;&#2352; &#2309; +&#2354;&#2380;&#2325;&#2367;&#2325; &#2310;&#2325;&#2366;&#2352;&#237 +9;&#2306; &#2357;&#2366;&#2354;&#2375; &#2332;&#2368;&#2357;&#2344; & +#2350;&#2306;&#2337;&#2352;&#2366; &#2352;&#2361;&#2375;&#2306; &#234 +1;&#2375;| </p> <p id=HI--1000-0003-1> &#2340;&#2349;&#2368; &#2319;&#2325; &#2325;&# +2336;&#2379;&#2352; &#2310;&#2342;&#2375;&#2358; &#2360;&#2369;&#2344 +;&#2366;&#2312; &#2342;&#2367;&#2351;&#2366;| &#2332;&#2379; &#2332;& +#2361;&#2366;&#2306; &#2361;&#2376;&#2306; &#2357;&#2361;&#2368; &#23 +52;&#2369;&#2325; &#2332;&#2366;&#2351;&#2375;| &#2344;&#2380;&#2360; +&#2376;&#2344;&#2367;&#2325; &#2309;&#2349;&#2381;&#2351;&#2366;&#236 +0; &#2330;&#2354; &#2352;&#2361;&#2366; &#2361;&#2376;| </p> <p id=HI--1000-0003-2> &#2311;&#2306;&#2332;&#2344; &#2348;&#2306;&#2 +342; &#2325;&#2352; &#2342;&#2367;&#2351;&#2375; &#2327;&#2351;&#2375 +;| &#2360;&#2348; &#2325;&#2369;&#2331; &#2358;&#2366;&#2306;&#2340; +&#2361;&#2379;&#2325;&#2352; &#2336;&#2361;&#2352; &#2327;&#2351;&#23 +66;| &#2309;&#2330;&#2366;&#2344;&#2325; &#2313;&#2340;&#2381;&#2340; +&#2350; &#2325;&#2379; &#2350;&#2370;&#2306;&#2327;&#2375; &#2325;&#2 +368; &#2330;&#2335;&#2335;&#2366;&#2344;&#2379;&#2306; &#2325;&#2375; + &#2348;&#2368;&#2330; &#2350;&#2375;&#2306; &#2319;&#2325; &#2357;&# +2367;&#2330;&#2367;&#2340;&#2381;&#2352; &#2360;&#2368; &#2330;&#2368 +;&#2332; &#2346;&#2337;&#2368; &#2361;&#2369;&#2312; &#2342;&#2367;&# +2326;&#2366;&#2312; &#2342;&#2368;| &#2351;&#2361; &#2330;&#2367;&#23 +25;&#2344;&#2368; &#2360;&#2368; &#2330;&#2368;&#2332; &#2341;&#2368; + &#2324;&#2352; &#2310;&#2360;&#2346;&#2366;&#2360; &#2325;&#2368; &# +2352;&#2306;&#2327;-&#2348;&#2367;&#2352;&#2306;&#2327;&#2368; &#2330 +;&#2368;&#2332;&#2379;&#2306; &#2325;&#2375; &#2348;&#2368;&#2330; &# +2351;&#2361; &#2309;&#2360;&#2366;&#2350;&#2366;&#2344;&#2381;&#2351; + &#2360;&#2375; &#2319;&#2325; &#2361;&#2368; &#2352;&#2306;&#2327; & +#2325;&#2368; &#2341;&#2368;| &#2351;&#2361; &#2325;&#2367;&#2360;&#2 +368; &#2349;&#2368; &#2332;&#2368;&#2357;&#2367;&#2340; &#2332;&#2306 +;&#2340;&#2369; &#2360;&#2375; &#2344;&#2361;&#2368;&#2306; &#2350;&# +2367;&#2354;&#2340;&#2368; &#2341;&#2368;| &#2332;&#2367;&#2332;&#238 +1;&#2334;&#2366;&#2360;&#2369; &#2313;&#2340;&#2381;&#2340;&#2350; &# +2344;&#2375; &#2313;&#2360;&#2375; &#2313;&#2336;&#2366; &#2354;&#236 +6;&#2344;&#2375; &#2325;&#2366; &#2310;&#2342;&#2375;&#2358; &#2342;& +#2375; &#2342;&#2367;&#2351;&#2366;| </p> <p id=HI--1000-0003-3> &#2351;&#2361; &#2319;&#2325; &#2348;&#2337;&# +2375; &#2310;&#2325;&#2366;&#2352; &#2325;&#2366; &#2313;&#2354;&#238 +1;&#2325;&#2366; &#2346;&#2367;&#2306;&#2337; &#2341;&#2366;| &#2313; +&#2340;&#2381;&#2340;&#2350; &#2348;&#2361;&#2369;&#2340; &#2326;&#23 +69;&#2358; &#2361;&#2369;&#2310;| &#2313;&#2360;&#2344;&#2375; &#2320 +;&#2360;&#2368; &#2325;&#2379;&#2312; &#2330;&#2368;&#2332; &#2325;&# +2349;&#2368; &#2346;&#2361;&#2354;&#2375; &#2344;&#2361;&#2368;&#2306 +; &#2342;&#2375;&#2326;&#2368; &#2341;&#2368;- &#2344; &#2360;&#2350; +&#2369;&#2342;&#2381;&#2352; &#2350;&#2375;&#2306; &#2324;&#2352; &#2 +344; &#2332;&#2350;&#2368;&#2344; &#2346;&#2352;| &#2309;&#2306;&#234 +0;&#2352;&#2367;&#2325;&#2381;&#2359; &#2351;&#2366;&#2340;&#2381;&#2 +352;&#2366; &#2324;&#2352; &#2346;&#2366;&#2344;&#2368; &#2350;&#2375 +;&#2306; &#2352;&#2361;&#2344;&#2375; &#2346;&#2352; &#2349;&#2368; & +#2311;&#2360; &#2330;&#2368;&#2332; &#2325;&#2366; &#2352;&#2306;&#23 +27; &#2324;&#2352; &#2310;&#2325;&#2366;&#2352; &#2344;&#2361;&#2368; +&#2306; &#2348;&#2342;&#2354;&#2366; &#2341;&#2366;| </p> <p id=HI--1000-0004-1> 4 &#2309;&#2306;&#2340;&#2352;&#2367;&#2325;&#2 +381;&#2359; &#2325;&#2366; &#2357;&#2352;&#2342;&#2366;&#2344; &#2336 +;&#2361;&#2352;&#2375; &#2352;&#2361;&#2344;&#2375; &#2325;&#2368; &# +2330;&#2375;&#2340;&#2366;&#2357;&#2344;&#2368; &#2326;&#2340;&#2381; +&#2350; &#2361;&#2379; &#2327;&#2351;&#2368; &#2341;&#2368;| &#2313;& +#2340;&#2381;&#2340;&#2350; &#2344;&#2375; &#2314;&#2346;&#2352; &#23 +32;&#2366;&#2344;&#2375; &#2325;&#2366; &#2310;&#2342;&#2375;&#2358; +&#2342;&#2367;&#2351;&#2366;| &#2346;&#2361;&#2369;&#2306;&#2330;&#23 +40;&#2375; &#2361;&#2368; &#2313;&#2360;&#2344;&#2375; &#2309;&#2346; +&#2344;&#2375; &#2350;&#2367;&#2340;&#2381;&#2352; &#2325;&#2366;&#23 +57;&#2366;&#2354;&#2370;&#2352; &#2348;&#2375;&#2343;&#2358;&#2366;&# +2354;&#2366; &#2325;&#2381;&#2359;&#2375;&#2340;&#2381;&#2352; &#2350 +;&#2375;&#2306; &#2360;&#2381;&#2341;&#2367;&#2340; &#2340;&#2366;&#2 +352;&#2366;&#2350;&#2306;&#2337;&#2354; &#2360;&#2381;&#2325;&#2370;& +#2354; &#2325;&#2375; &#2346;&#2381;&#2352;&#2379;&#2347;&#2375;&#236 +0;&#2352; &#2350;&#2366;&#2352;&#2369;&#2340;&#2367; &#2325;&#2379; & +#2335;&#2375;&#2354;&#2368;&#2347;&#2379;&#2344; &#2325;&#2367;&#2351 +;&#2366; &#2324;&#2352; &#2311;&#2360; &#2313;&#2354;&#2381;&#2325;&# +2366; &#2346;&#2367;&#2337; &#2325;&#2375; &#2348;&#2366;&#2352;&#237 +5; &#2350;&#2375;&#2306; &#2313;&#2344;&#2381;&#2361;&#2375;&#2306; & +#2348;&#2340;&#2366;&#2351;&#2366;| &#2346;&#2381;&#2352;&#2379;&#234 +7;&#2375;&#2360;&#2352; &#2350;&#2366;&#2352;&#2369;&#2340;&#2367; &# +2348;&#2361;&#2369;&#2340; &#2313;&#2340;&#2381;&#2360;&#2366;&#2361; + &#2350;&#2375;&#2306; &#2310; &#2327;&#2351;&#2375; &#2341;&#2375;| +&#2309;&#2348; &#2340;&#2325; &#2313;&#2344;&#2381;&#2361;&#2379;&#23 +06;&#2344;&#2375; &#2332;&#2367;&#2340;&#2344;&#2375; &#2349;&#2368; +&#2313;&#2354;&#2381;&#2325;&#2366; &#2346;&#2367;&#2306;&#2337;&#237 +9;&#2306; &#2325;&#2375; &#2348;&#2366;&#2352;&#2375; &#2350;&#2375;& +#2306; &#2360;&#2369;&#2344;&#2366; &#2341;&#2366;, &#2351;&#2361; &# +2313;&#2344; &#2360;&#2348;&#2360;&#2375; &#2348;&#2337;&#2366; &#234 +1;&#2366;| &#2311;&#2360;&#2325;&#2366; &#2346;&#2352;&#2368;&#2325;& +#2381;&#2359;&#2339; &#2325;&#2352;&#2344;&#2375; &#2325;&#2368; &#23 +09;&#2344;&#2369;&#2350;&#2340;&#2367; &#2350;&#2367;&#2354;&#2340;&# +2375; &#2361;&#2368; &#2346;&#2381;&#2352;&#2379;&#2347;&#2375;&#2360 +;&#2352; &#2350;&#2366;&#2352;&#2369;&#2340;&#2367; &#2344;&#2375; &# +2309;&#2306;&#2340;&#2352;&#2367;&#2325;&#2381;&#2359; &#2325;&#2375; + &#2311;&#2360; &#2309;&#2357;&#2358;&#2375;&#2359; &#2346;&#2352; &# +2346;&#2352;&#2368;&#2325;&#2381;&#2359;&#2339; &#2325;&#2352;&#2344; +&#2366; &#2358;&#2369;&#2352;&#2369; &#2325;&#2352; &#2342;&#2367;&#2 +351;&#2366;| </p> <p id=HI--1000-0005-1> 5 &#2311;&#2360; &#2346;&#2352; &#2332;&#2350;& +#2368; &#2348;&#2366;&#2361;&#2352;&#2368; &#2340;&#2361;&#2379;&#230 +6; &#2325;&#2379; &#2313;&#2340;&#2366;&#2352;&#2344;&#2375; &#2325;& +#2375; &#2348;&#2366;&#2342; &#2319;&#2325; &#2360;&#2381;&#2346;&#23 +59;&#2381;&#2335; &#2310;&#2325;&#2371;&#2340;&#2367; &#2360;&#2366;& +#2350;&#2344;&#2375; &#2310;&#2351;&#2368; &#2332;&#2379; 10101 &#233 +2;&#2376;&#2360;&#2375; &#2342;&#2367;&#2326; &#2352;&#2361;&#2368; & +#2341;&#2368;| &#2346;&#2381;&#2352;&#2379;&#2347;&#2375;&#2360;&#235 +2; &#2344;&#2375; &#2348;&#2340;&#2366;&#2351;&#2366; &#2325;&#2367; +&#2351;&#2361; 21 &#2325;&#2366; &#2342;&#2367;&#2357;&#2330;&#2352; +&#2346;&#2381;&#2352;&#2339;&#2366;&#2354;&#2368; &#2325;&#2366; &#23 +52;&#2369;&#2346; &#2361;&#2376;| &#2324;&#2352; 21 &#2325;&#2366; &# +2309;&#2352;&#2381;&#2341; &#2309;&#2306;&#2340;&#2352;&#2367;&#2325; +&#2381;&#2359; &#2350;&#2375;&#2306; &#2361;&#2366;&#2311;&#2337;&#23 +81;&#2352;&#2379;&#2332;&#2344; &#2325;&#2368; 21 &#2360;&#2375;&#230 +6;&#2335;&#2368;&#2350;&#2368;&#2335;&#2352; &#2352;&#2375;&#2337;&#2 +367;&#2351;&#2379;&#2306; &#2310;&#2357;&#2371;&#2340;&#2381;&#2340;& +#2367; &#2361;&#2376;| </p> <p id=HI--1000-0005-2> &#2325;&#2361;&#2368; &#2351;&#2361; &#2348;&# +2366;&#2361;&#2381;&#2352;&#2351; &#2309;&#2306;&#2340;&#2352;&#2367; +&#2325;&#2381;&#2359; &#2325;&#2375; &#2325;&#2367;&#2360;&#2368; &#2 +360;&#2350;&#2333;&#2342;&#2366;&#2352; &#2346;&#2381;&#2352;&#2366;& +#2339;&#2368; &#2325;&#2366; &#2360;&#2306;&#2342;&#2375;&#2358; &#23 +40;&#2379; &#2344;&#2361;&#2368;&#2306; &#2361;&#2376;| </p> <p id=HI--1000-0005-3> &#2325;&#2312; &#2357;&#2352;&#2381;&#2359;&#2 +379; &#2360;&#2375; &#2346;&#2371;&#2341;&#2381;&#2357;&#2368; &#2325 +;&#2375; &#2357;&#2376;&#2332;&#2381;&#2334;&#2366;&#2344;&#2367;&#23 +25; &#2360;&#2366;&#2306;&#2325;&#2375;&#2340;&#2367;&#2325; &#2346;& +#2381;&#2352;&#2366;&#2341;&#2350;&#2367;&#2325; &#2327;&#2339;&#2367 +;&#2340;&#2368;&#2351; &#2360;&#2306;&#2342;&#2375;&#2358;&#2379;&#23 +06; &#2325;&#2379; &#2311;&#2360; &#2310;&#2358;&#2366; &#2325;&#2375 +; &#2360;&#2366;&#2341; &#2348;&#2366;&#2361;&#2352; &#2349;&#2375;&# +2332;&#2340;&#2375; &#2361;&#2376;&#2306; &#2325;&#2367; &#2313;&#234 +4;&#2381;&#2361;&#2375;&#2306; &#2325;&#2379;&#2312; &#2327;&#2381;&# +2352;&#2361;&#2339; &#2325;&#2352;&#2375;&#2327;&#2366;| &#2346;&#235 +2; &#2309;&#2349;&#2368; &#2340;&#2325; &#2340;&#2379; &#2325;&#2379; +&#2312; &#2332;&#2357;&#2366;&#2348; &#2344;&#2361;&#2368;&#2306; &#2 +350;&#2367;&#2354;&#2366; &#2341;&#2366;| &#2325;&#2381;&#2351;&#2366 +; &#2351;&#2361; &#2325;&#2379;&#2312; &#2332;&#2357;&#2366;&#2348; & +#2361;&#2379; &#2360;&#2325;&#2340;&#2366; &#2361;&#2376;? </p> <p id=HI--1000-0006-1> 6 &#2309;&#2306;&#2340;&#2352;&#2367;&#2325;&#2 +381;&#2359; &#2325;&#2366; &#2357;&#2352;&#2342;&#2366;&#2344; &#2313 +;&#2354;&#2381;&#2325;&#2366;&#2346;&#2367;&#2306;&#2337; &#2360;&#23 +75; &#2346;&#2381;&#2352;&#2366;&#2346;&#2381;&#2340; &#2360;&#2306;& +#2342;&#2375;&#2358; &#2311;&#2360; &#2313;&#2354;&#2381;&#2325;&#2 +366;&#2346;&#2367;&#2306;&#2337; &#2324;&#2352; &#2311;&#2360;&#2325; +&#2375; &#2342;&#2367;&#2357;&#2330;&#2352; &#2360;&#2306;&#2342;&#23 +75;&#2358; &#2325;&#2368; &#2326;&#2348;&#2352; &#2346;&#2370;&#2352; +&#2368; &#2342;&#2369;&#2344;&#2367;&#2351;&#2366; &#2325;&#2375; &#2 +352;&#2375;&#2337;&#2367;&#2351;&#2379; &#2360;&#2381;&#2335;&#2375;& +#2358;&#2344;&#2379;&#2306; &#2360;&#2375; &#2346;&#2381;&#2352;&#236 +0;&#2366;&#2352;&#2367;&#2340; &#2361;&#2379; &#2327;&#2351;&#2368;| +&#2309;&#2350;&#2352;&#2368;&#2325;&#2367;&#2351;&#2379;&#2306; &#234 +4;&#2375; &#2328;&#2379;&#2359;&#2339;&#2366; &#2325;&#2368; &#2325;& +#2367; &#2357;&#2375; &#2319;&#2325; &#2357;&#2367;&#2358;&#2375;&#23 +59; &#2309;&#2306;&#2340;&#2352;&#2367;&#2325;&#2381;&#2359; &#2351;& +#2366;&#2344; &#2348;&#2344;&#2366;&#2351;&#2375;&#2327;&#2375;&#2306 +; &#2324;&#2352; &#2311;&#2360;&#2375; &#2348;&#2366;&#2361;&#2381;&# +2352;&#2351; &#2309;&#2306;&#2340;&#2352;&#2367;&#2325;&#2381;&#2359; + &#2325;&#2375; &#2313;&#2360; &#2325;&#2381;&#2359;&#2375;&#2340;&#2 +381;&#2352; &#2325;&#2368; &#2326;&#2379;&#2332; &#2325;&#2375; &#235 +4;&#2367;&#2319; &#2349;&#2375;&#2332;&#2375;&#2306;&#2327;&#2375; &# +2332;&#2361;&#2377; &#2344;&#2351;&#2375; &#2332;&#2368;&#2357; &#232 +5;&#2366; &#2309;&#2349;&#2381;&#2351;&#2369;&#2342;&#2351; &#2361;&# +2369;&#2310; &#2361;&#2376;| &#2342;&#2370;&#2360;&#2352;&#2368; &#23 +23;&#2352; &#2352;&#2369;&#2360;&#2368; &#2354;&#2379;&#2327; &#2360; +&#2366;&#2357;&#2343;&#2366;&#2344;&#2368; &#2360;&#2375; &#2361;&#23 +68; &#2325;&#2379;&#2312; &#2325;&#2342;&#2350; &#2313;&#2336;&#2366; +&#2344;&#2366; &#2330;&#2366;&#2361;&#2340;&#2375; &#2341;&#2375; &#2 +324;&#2352; &#2340;&#2348; &#2340;&#2325; &#2346;&#2381;&#2352;&#2340 +;&#2368;&#2325;&#2381;&#2359;&#2366; &#2325;&#2352;&#2344;&#2366; &#2 +330;&#2366;&#2361;&#2340;&#2375; &#2341;&#2375; &#2332;&#2348; &#2340 +;&#2325; &#2325;&#2367; &#2342;&#2367;&#2357;&#2330;&#2352; &#2346;&# +2381;&#2352;&#2339;&#2366;&#2354;&#2368; &#2360;&#2375; &#2361;&#2368 +;, &#2313;&#2344;&#2360;&#2375; &#2346;&#2370;&#2352;&#2368; &#2340;& +#2352;&#2361; &#2360;&#2306;&#2346;&#2352;&#2381;&#2325; &#2344;&#236 +1;&#2368; &#2325;&#2352; &#2354;&#2367;&#2351;&#2366; &#2332;&#2366;& +#2340;&#2366;| </p> <p id=HI--1000-0006-2> &#2348;&#2361;&#2369;&#2340; &#2360;&#2375; &# +2335;&#2375;&#2354;&#2368;&#2327;&#2381;&#2352;&#2366;&#2350; &#2311; +&#2360; &#2348;&#2366;&#2340; &#2325;&#2368; &#2357;&#2325;&#2366;&#2 +354;&#2340; &#2325;&#2352; &#2352;&#2361;&#2375; &#2341;&#2375; &#232 +5;&#2367; &#2325;&#2367;&#2360;&#2368; &#2349;&#2368; &#2340;&#2352;& +#2361; &#2325;&#2375; &#2360;&#2306;&#2330;&#2366;&#2352; &#2325;&#23 +79; &#2352;&#2379;&#2325; &#2342;&#2367;&#2351;&#2366; &#2332;&#2366; +&#2351;&#2375;, &#2325;&#2361;&#2368;&#2306; &#2320;&#2360;&#2366; &# +2344; &#2361;&#2379; &#2325;&#2367; &#2357;&#2361; &#2342;&#2370;&#23 +60;&#2352;&#2368; &#2360;&#2350;&#2381;&#2351;&#2340;&#2366; &#2361;& +#2350;&#2366;&#2352;&#2368; &#2346;&#2381;&#2352;&#2380;&#2342;&#2381 +;&#2351;&#2379;&#2327;&#2367;&#2325;&#2368; &#2325;&#2379; &#2309;&#2 +349;&#2368; &#2310;&#2342;&#2367;&#2350;&#2325;&#2366;&#2354;&#2368;& +#2344; &#2361;&#2368; &#2360;&#2350;&#2333;&#2381; &#2352;&#2361;&#23 +68; &#2361;&#2379;| &#2325;&#2369;&#2331; &#2324;&#2352; &#2354;&#237 +9;&#2327;&#2379;&#2306; &#2325;&#2366; &#2340;&#2352;&#2381;&#2325; & +#2341;&#2366; &#2325;&#2367; &#2332;&#2379; &#2360;&#2349;&#2381;&#23 +51;&#2340;&#2366; &#2311;&#2340;&#2344;&#2375; &#2360;&#2350;&#2351; +&#2340;&#2325; &#2332;&#2368;&#2357;&#2367;&#2340; &#2325;&#2352; &#2 +360;&#2325;&#2340;&#2368; &#2361;&#2376;&#2306;, &#2313;&#2360;&#2325 +;&#2375; &#2311;&#2352;&#2366;&#2342;&#2379;&#2306; &#2325;&#2375; &# +2348;&#2369;&#2352;&#2375; &#2361;&#2379;&#2344;&#2375; &#2325;&#2368 +; &#2360;&#2306;&#2349;&#2366;&#2357;&#2344;&#2366; &#2325;&#2350; &# +2361;&#2368; &#2354;&#2327;&#2340;&#2368; &#2361;&#2376;| &#2311;&#23 +60;&#2325;&#2375; &#2360;&#2366;&#2341; &#2360;&#2306;&#2346;&#2352;& +#2381;&#2325; &#2326;&#2340;&#2352;&#2344;&#2366;&#2325; &#2360;&#236 +7;&#2342;&#2381;&#2357; &#2344;&#2361;&#2368;&#2306; &#2361;&#2379;&# +2327;&#2366; &#2348;&#2354;&#2381;&#2325;&#2367; &#2354;&#2366;&#2349 +;&#2325;&#2366;&#2352;&#2368; &#2361;&#2368; &#2361;&#2379; &#2360;&# +2325;&#2340;&#2366; &#2361;&#2376;| &#2346;&#2381;&#2352;&#2379;&#234 +7;&#2375;&#2360;&#2352; &#2350;&#2366;&#2352;&#2369;&#2340;&#2367; &# +2348;&#2366;&#2361;&#2381;&#2352;&#2351; &#2309;&#2306;&#2340;&#2352; +&#2367;&#2325;&#2381;&#2359; &#2350;&#2375;&#2306; &#2349;&#2375;&#23 +32;&#2344;&#2375; &#2325;&#2375; &#2354;&#2367;&#2319; &#2360;&#2306; +&#2342;&#2375;&#2358; &#2340;&#2376;&#2351;&#2366;&#2352; &#2325;&#23 +52;&#2344;&#2375; &#2350;&#2375;&#2306; &#2354;&#2327; &#2327;&#2351; +&#2375;| &#2313;&#2344;&#2381;&#2361;&#2379;&#2306;&#2344;&#2375;&#23 +06; &#2360;&#2306;&#2342;&#2375;&#2358; &#2325;&#2366; &#2360;&#2306; +&#2325;&#2375;&#2340; &#2325;&#2352;&#2344;&#2375; &#2325;&#2368; &#2 +319;&#2325; &#2320;&#2360;&#2368; &#2346;&#2381;&#2352;&#2339;&#2366; +&#2354;&#2368; &#2340;&#2376;&#2351;&#2366;&#2352; &#2325;&#2368; &#2 +332;&#2379; &#2344;&#2367;&#2360;&#2381;&#2360;&#2306;&#2342;&#2375;& +#2361; &#2360;&#2350;&#2333;&#2381;&#2342;&#2366;&#2352; &#2346;&#238 +1;&#2352;&#2366;&#2339;&#2367;&#2351;&#2379;&#2306; &#2342;&#2381;&#2 +357;&#2366;&#2352;&#2366; &#2349;&#2375;&#2332;&#2368; &#2327;&#2351; +&#2368; &#2361;&#2368; &#2350;&#2366;&#2344;&#2368; &#2332;&#2366;&#2 +351;&#2375;&#2327;&#2368;| &#2313;&#2344;&#2381;&#2361;&#2379;&#2306; +&#2344;&#2375; &#2325;&#2361;&#2366; &#2325;&#2367; &#2357;&#2367;&#2 +325;&#2367;&#2352;&#2339; &#2325;&#2368; &#145;&#2321;&#2344;-&#2310; +&#2347;&#146; &#2325;&#2375; &#2319;&#2325; &#2309;&#2344;&#2369;&#23 +25;&#2381;&#2352;&#2350; &#2342;&#2381;&#2357;&#2366;&#2352;&#2366; & +#2360;&#2306;&#2342;&#2375;&#2358; &#2349;&#2375;&#2332;&#2366; &#233 +2;&#2366; &#2360;&#2325;&#2340;&#2366; 7 &#2361;&#2376;| &#2340;&# +2352;&#2306;&#2327; &#2325;&#2366; &#2309;&#2352;&#2381;&#2341; &#236 +1;&#2379;&#2327;&#2366; &#2319;&#2325; &#2324;&#2352; &#2344; &#2361; +&#2379;&#2344;&#2375; &#2325;&#2366; &#2309;&#2352;&#2381;&#2341; &#2 +361;&#2379;&#2327;&#2366; &#2358;&#2370;&#2344;&#2381;&#2351;| &#2311 +;&#2360; &#2346;&#2381;&#2352;&#2325;&#2366;&#2352; &#2342;&#2367;&#2 +357;&#2330;&#2352; &#2358;&#2381;&#2352;&#2375;&#2339;&#2368; &#2325; +&#2368; &#2360;&#2306;&#2326;&#2381;&#2351;&#2366;&#2323;&#2306; &#23 +25;&#2379; &#2346;&#2381;&#2352;&#2375;&#2359;&#2367;&#2340; &#2325;& +#2367;&#2351;&#2366; &#2332;&#2366; &#2360;&#2325;&#2340;&#2366; &#23 +61;&#2376;&#2306;| &#2347;&#2367;&#2352;, &#2351;&#2375; &#2360;&#230 +6;&#2326;&#2381;&#2351;&#2366;&#2317; &#2346;&#2361;&#2354;&#2368; &# +2348;&#2366;&#2352;&#2361; &#2352;&#2369;&#2338; &#2360;&#2306;&#2326 +;&#2381;&#2351;&#2366;&#2317; &#2349;&#2368; &#2361;&#2379; &#2360;&# +2325;&#2340;&#2368; &#2361;&#2376;- 1,2,3,5,7,11,13,17,19,23,29,31 &# +2351;&#2361; &#2360;&#2366;&#2350;&#2366;&#2344;&#2381;&#2351; &#2327 +;&#2339;&#2367;&#2340;&#2368;&#2351; &#2332;&#2381;&#2334;&#2366;&#23 +44; &#2325;&#2368; &#2323;&#2352; &#2311;&#2306;&#2327;&#2367;&#2340; + &#2325;&#2352;&#2375;&#2327;&#2366; &#2332;&#2379; &#2360;&#2367;&#2 +352;&#2381;&#2347; 8 &#2309;&#2306;&#2340;&#2352;&#2367;&#2325;&#238 +1;&#2359; &#2325;&#2366; &#2357;&#2352;&#2342;&#2366;&#2344; &#2360;& +#2350;&#2333;&#2342;&#2366;&#2352; &#2346;&#2381;&#2352;&#2366;&#2339 +;&#2367;&#2351;&#2379;&#2306; &#2325;&#2368; &#2323;&#2352; &#2360;&# +2375; &#2361;&#2368; &#2310; &#2360;&#2325;&#2340;&#2366; &#2361;&#23 +76;&#2306; &#2319;&#2325; &#2360;&#2381;&#2346;&#2359;&#2381;&#2335; +&#2357;&#2367;&#2357;&#2352;&#2339; &#2342;&#2375;&#2344;&#2375; &#23 +25;&#2375; &#2354;&#2367;&#2319; &#2311;&#2360; &#2346;&#2381;&#2352; +&#2325;&#2366;&#2352; &#2325;&#2375; &#2360;&#2306;&#2342;&#2358; &#2 +325;&#2379; &#2325;&#2381;&#2352;&#2350;&#2348;&#2342;&#2381;&#2357; +&#2325;&#2352;&#2344;&#2375; &#2325;&#2368; &#2346;&#2381;&#2352;&#23 +39;&#2366;&#2354;&#2368; &#2349;&#2368; &#2340;&#2376;&#2351;&#2366;& +#2352; &#2325;&#2368; &#2332;&#2366; &#2360;&#2325;&#2340;&#2368; &#2 +361;&#2376;| 19 &#2357;&#2352;&#2381;&#2327;&#2379; &#2325;&#2375; 29 + &#2360;&#2350;&#2370;&#2361;&#2379;&#2306; &#2325;&#2375; &#2357;&#2 +367;&#2344;&#2381;&#2351;&#2366;&#2360; &#2360;&#2375;&#150;&#2350;&# +2360;&#2354;&#2344; &#2312;&#2325;&#2366;&#2312;&#2351;&#2379; &#2325 +;&#2379; &#2325;&#2366;&#2354;&#2366; &#2324;&#2352; &#2358;&#2370;&# +2344;&#2381;&#2351;&#2379; &#2325;&#2379; &#2360;&#2347;&#2375;&#2342 +; &#2325;&#2352;&#2325;&#2375;- &#2319;&#2325; &#2342;&#2367;&#2354;& +#2330;&#2360;&#2381;&#2346; &#2330;&#2367;&#2340;&#2381;&#2352; &#234 +8;&#2344;&#2366;&#2351;&#2366; &#2332;&#2366; &#2360;&#2325;&#2340;&# +2366; &#2361;&#2376;&#2306; &#2332;&#2379; &#2350;&#2366;&#2344;&#235 +7; &#2309;&#2360;&#2381;&#2340;&#2367;&#2340;&#2381;&#2357; &#2325;&# +2375; &#2349;&#2380;&#2340;&#2367;&#2325; &#2360;&#2381;&#2357;&#2352 +;&#2369;&#2346;, &#2360;&#2380;&#2352; &#2346;&#2381;&#2352;&#2339;&# +2366;&#2354;&#2368; &#2325;&#2368; &#2325;&#2366;&#2352;&#2381;&#2351 +;&#2357;&#2367;&#2343;&#2367; &#2340;&#2341;&#2366; &#2309;&#2344;&#2 +381;&#2351; &#2350;&#2361;&#2340;&#2381;&#2357;&#2346;&#2370;&#2352;& +#2381;&#2339; &#2340;&#2341;&#2381;&#2351;&#2379;&#2306; &#2325;&#237 +9; &#2346;&#2381;&#2352;&#2325;&#2335; &#2325;&#2352; &#2360;&#2325;& +#2340;&#2366; &#2361;&#2376;| </p> <p id=HI--1000-0008-1> &#2340;&#2349;&#2368; &#2310;&#2351;&#2369;&#2 +352;&#2381;&#2357;&#2367;&#2332;&#2381;&#2334;&#2366;&#2344; &#2309;& +#2344;&#2369;&#2360;&#2306;&#2343;&#2366;&#2344; &#2346;&#2352;&#2367 +;&#2359;&#2342; &#2325;&#2368; &#2323;&#2352; &#2360;&#2375; &#2319;& +#2325; &#2360;&#2306;&#2342;&#2375;&#2358; &#2350;&#2367;&#2354;&#236 +6;| &#2332;&#2368;&#2357; &#2352;&#2360;&#2366;&#2351;&#2344; &#2357; +&#2367;&#2349;&#2366;&#2327; &#2325;&#2375; &#2309;&#2343;&#2381;&#23 +51;&#2325;&#2381;&#2359; &#2337;&#2366;&#2325;&#2381;&#2335;&#2352; & +#2343;&#2344;&#2357;&#2306;&#2340;&#2352;&#2368; &#2325;&#2361; &#235 +2;&#2361;&#2375; &#2341;&#2375;| </p>
        but the problem am facing is that @ each run of the loop it just scans the whole file and not the single line
        I'm not entirely sure what you mean here. You mean grep (the command line tool) goes through the whole file every time? Uh, yeah, that's what it does. If you don't want that, you could rewrite grep in perl, I mean incorporate the functionality of grep that you want as a routine in your script, so that it works on only one line. It's not that hard, after all, ack is an extended grep which is written in Perl. Basically you just need to test the regexp on the line.
Re: shell commands doesn't integrate with perl
by ww (Archbishop) on Jul 15, 2011 at 12:20 UTC
    It would also be more readable if you indented and avoided placing multiple statements on single lines (002, for example)
Re: shell commands doesn't integrate with perl
by graff (Chancellor) on Jul 16, 2011 at 05:46 UTC
    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).

      this code doesn't work @all, all it does is flooding my screen with asterisks. please do refer to the sample data files i've posted. appreciate ur help very much

        Which just means it doesn't find any of the patterns you are looking for. If I look at your test data, the patterns all look like "EN-1000-0002-1", while the files have ids like "EN--1000-0002-1". a remarkably obvious difference. No wonder the script doesn't find anything
Re: shell commands doesn't integrate with perl
by Anonymous Monk on Jul 15, 2011 at 12:21 UTC

      no it's not a duplicate. the post was in 1 sense much of the same as a problem i faced.