vikashiiitdm has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks, i've been trying to make a script to read keys from a file named labels, each line contains some keys like EN-***|HI-*** these can be further having more keys like EN can have EN-*** : EN-***. I have to read this file , then process each line to extract all EN and hi keys..... and for each line print the corresponding data from files en_1000 and HI_1000, so that all this information about a line comes together. i have written this code but it somehow fails to work as i wish. the output should be like all english info from the keys , and then hindi info from the same line of keys. i.e. info from EN-1000-0002-1 then info from HI-1000-0001-1 and then from HI-1000-0002-1. on next run info from the other line of labels.please enlighten me with ur knowledge.
The sample labels file is:-#!/bin/env perl open (LABEL,"<labels") or die $!; @lines=<LABEL>; close LABEL; print @lines; open (HANDLEE,">final_result") or die $!; foreach $line (@lines) { (my $english_index, my $hindi_index, my $nua)=split(/\|/,$line); open (HANDLE,">en_index") or die $!; my @key_en=split(/:/,$english_index); print HANDLE @key_en,"\n"; open (HANDLE_HI,">hi_index") or die $!; print HANDLE_HI "$hindi_index\n"; my @key_hi=split(/:/,$hindi_index); print HANDLE_HI @key_hi,"\n"; foreach $keye (@key_en) { $linb=`grep --regexp '$_' /home/vikash/pro_1/en_1000`; print HANDLEE $linb; } foreach $keyh (@key_hi) { $linbh=`grep --regexp '$_' /home/vikash/pro_1/HI_1000`; print HANDLEE $linbh; } print HANDLEE "*****\n"; } close HANDLEE;
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| EN-1000-0008-4|HI-1000-0008-4| EN-1000-0009-1|HI-1000-0009-1| EN-1000-0009-2|HI-1000-0009-2| EN-1000-0009-3|HI-1000-0009-3| EN-1000-0009-4|HI-1000-0009-4| EN-1000-0010-1|HI-1000-0010-1| EN-1000-0010-2|HI-1000-0010-2| EN-1000-0010-3|HI-1000-0010-3| EN-1000-0010-4|HI-1000-0010-4| EN-1000-0010-5|HI-1000-0010-5:HI-1000-0012-1| EN-1000-0012-1|HI-1000-0012-2| EN-1000-0012-2|HI-1000-0012-3| EN-1000-0012-3|HI-1000-0012-4:HI-1000-0014-1:HI-1000-0014-2| EN-1000-0014-1|HI-1000-0014-3| EN-1000-0014-2|HI-1000-0014-4| EN-1000-0014-3|HI-1000-0015-1| EN-1000-0015-1|HI-1000-0015-2| EN-1000-0015-2|HI-1000-0016-1| EN-1000-0015-3|HI-1000-0016-2| EN-1000-0015-4|HI-1000-0016-3| EN-1000-0016-1|HI-1000-0016-4| EN-1000-0017-1|HI-1000-0017-1| EN-1000-0017-2|HI-1000-0017-2| EN-1000-0017-3|HI-1000-0017-3| EN-1000-0017-4|HI-1000-0017-4| EN-1000-0017-5|HI-1000-0017-5| EN-1000-0017-6|HI-1000-0017-6| EN-1000-0018-1|HI-1000-0018-1| EN-1000-0019-1|HI-1000-0019-1:HI-1000-0020-1| EN-1000-0020-1|HI-1000-0020-2| EN-1000-0020-2|HI-1000-0020-3| EN-1000-0022-1|HI-1000-0020-4| EN-1000-0022-2|HI-1000-0022-1| EN-1000-0022-3|HI-1000-0022-2| EN-1000-0022-4|HI-1000-0022-3| EN-1000-0022-5|HI-1000-0022-4:HI-1000-0022-5| EN-1000-0022-6|HI-1000-0022-6| EN-1000-0023-1|HI-1000-0023-1| EN-1000-0023-2|HI-1000-0023-2| EN-1000-0024-1|HI-1000-0023-2:HI-1000-0023-3| EN-1000-0024-2|HI-1000-0024-1| EN-1000-0026-1|HI-1000-0024-2:HI-1000-0026-1:HI-1000-0026-2| EN-1000-0028-1:EN-1000-0029-1|HI-1000-0028-1:HI-1000-0028-2:HI-1000-00 +28-3:HI-1000-0028-4:HI-1000-0028-5:HI-1000-0028-6:HI-1000-0028-7:HI-1 +000-0028-9:HI-1000-0029-1:HI-1000-0029-2| EN-1000-0029-2|HI-1000-0029-3| EN-1000-0030-1|HI-1000-0030-1:HI-1000-0030-2:HI-1000-0030-3| EN-1000-0030-2|HI-1000-0030-4| EN-1000-0030-3|HI-1000-0030-5| EN-1000-0030-4|HI-1000-0032-1| EN-1000-0030-5|HI-1000-0033-1| EN-1000-0034-1|HI-1000-0034-1| EN-1000-0036-1|HI-1000-0036-1| EN-1000-0036-2|HI-1000-0036-2| EN-1000-0036-3|HI-1000-0036-3| EN-1000-0036-4|HI-1000-0036-4| EN-1000-0036-5|HI-1000-0036-5| EN-1000-0036-6|HI-1000-0036-6| EN-1000-0038-1|HI-1000-0038-1| EN-1000-0038-2|HI-1000-0038-2| EN-1000-0038-3|HI-1000-0038-3| EN-1000-0040-1|HI-1000-0038-4| EN-1000-0040-2|HI-1000-0040-1:HI-1000-0040-2| EN-1000-0040-3|HI-1000-0040-3| EN-1000-0040-4|HI-1000-0040-4| EN-1000-0041-1|HI-1000-0040-5| EN-1000-0041-2|HI-1000-0041-1| EN-1000-0041-3|HI-1000-0041-2| EN-1000-0041-4|HI-1000-0041-3| EN-1000-0041-5|HI-1000-0041-4| EN-1000-0041-6|HI-1000-0041-5| EN-1000-0041-7|HI-1000-0041-6| EN-1000-0042-1|HI-1000-0042-1| EN-1000-0042-2|HI-1000-0042-2| EN-1000-0042-3|HI-1000-0042-3| EN-1000-0042-4|HI-1000-0042-4| EN-1000-0042-5|HI-1000-0043-1:HI-1000-0044-1| EN-1000-0044-1:HI-1000-0044-2|HI-1000-0044-2| EN-1000-0044-2|HI-1000-0044-3| EN-1000-0044-3|HI-1000-0047-1| EN-1000-0047-1|HI-1000-0047-2| EN-1000-0047-2|HI-1000-0047-3| EN-1000-0047-3|HI-1000-0047-4| EN-1000-0047-4|HI-1000-0047-5| EN-1000-0047-5|HI-1000-0047-6:HI-1000-0047-7| EN-1000-0049-1|HI-1000-0049-1| EN-1000-0050-1|HI-1000-0050-1| EN-1000-0050-2|HI-1000-0050-2| EN-1000-0050-3|HI-1000-0050-3:HI-1000-0052-1:HI-1000-0052-2:HI-1000-00 +52-3| EN-1000-0052-1|HI-1000-0052-4:HI-1000-0052-5:HI-1000-0052-6| EN-1000-0052-2|HI-1000-0052-7:HI-1000-0054-1:HI-1000-0054-2:HI-1000-00 +54-3| EN-1000-0054-1|HI-1000-0054-4| EN-1000-0054-2|HI-1000-0056-1| EN-1000-0056-1|HI-1000-0056-2|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file handling in perl whatz the problem???
by thargas (Deacon) on Jul 15, 2011 at 12:24 UTC | |
by davido (Cardinal) on Jul 15, 2011 at 15:15 UTC | |
by vikashiiitdm (Novice) on Jul 18, 2011 at 09:25 UTC |