Dear monks,
would you be so kind to help my simplify the following code(which also i tried to simplify up to now, since the last time we spoke).
this is the code:
$dat0 = 'a.txt';
open(DAT, "$dat0") || die("Could not open file!");
@all=<DAT>;
@temp = '';
$temp[0] = $temp[1] = '';
$l = 1;
foreach $i (@all) {
$temp[$l * 2] = $i;
@u = split (/ /, $i);
foreach $j (@u){
if (($j ne "$j") || ($j ne "v")) {
@tep = '';$tep1 = 0;
foreach $k (@all) {
@uuu = split (/ /, $k);
chomp $j;
if ($uuu[0] eq "$j") {
$tep[$tep1] = \$k;
$tep1++;}
}
$temp[$l * 2 + 1] = \@tep;
}
}
$l++;}
open(DAT, ">$dat0") || die;
print DAT @all;
close(DAT);
It works file for a file where are 3, 4 lines, but when i comes to thousands, it takes about 10 seconds to work on one line.
How can it be simplisied ?
ps : this script is supposed to get all the lines from a file and refer each word to the sentence that starts with that word (and, there aren't 2 sentences that start identically).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.