Q:
I have to read data from a file but wile reading I have to come back to
the bedinning of the file and look through it several times. I need an
advise how to do it. I did:
@lines = <INfO>
while ($x <= $#lines)
if (//)
{do
open DATA
@stroki = <DATA>
close DATA
while ($flag<= $#stroki)
{if (//) {do}
}
}
________________________________
@lines = <INFO>;
while ($x <= $#lines)
{
if ($lines[$x] =~ /^[Uu]n (\S+)|^[Uu]ne (\S+)|^[Ll][ea] (\S+)/) {
if ($lines[$x] =~ /^\S+\s(\S+).*; c'est aussi (.+); c'est \\\'egalement
(.+)/)
{ #print "$lines[$x]";
$slovo= $1; $part1 = $2; $part2 = $3;
if ($slovo =~/.+,/){chop ($slovo);}
open (DATA,$file1) or die "Can't open $file: $!";
@stroki = <DATA>;
close (DATA);
while ($flag <= $#stroki)
{ if ($stroki[$flag] =~ /<entry id=$slovo/)
{ print "$stroki[$flag]\n";
$flag +=1;
last;}
else {$flag +=1;}
}
} # $x +=1;
$x +=1;
}
else {$x +=1;}
}
INFO and DATA are the same file. The programm finds line containing "entry
id=$slovo" only twice.
I willl be extremely thankful for any reply.
A:
Read all the file into memory if this is smaller than a few 100MB.
If the file is 1G approx then use 'seek' to reposition the file pointer.
Regards,
Peter
[ back to toc ]