Using $file as the name of the file, open up a filehandle for each text file. Then you can loop through to the 32nd line and grab it. Then close the file and open the next one. Try this:
foreach $file (@userff)
{
open (IN, $file) or die "Can't open $file.";
for ($i = 1; $i <= 32; $i++)
{
$line = <IN>;
}
# $line now = line 32
push $line @userii;
close IN;
}
I can't think of a more efficient way, but there may be one. --Derek
"Fear not the storm for this is where we grow strong."
i guess the following code will work
foreach $file(@userff)
{
open(FILEHANDLE,$file) || die "cann't open the $file!";
@filearray=<FILEHANDLE>;
close(FILEHANDLE);
$i=0;
$line32;
LINE:
foreach $line(@filearray)
{
$line32=$line;
#here $line32 takes each time a new line
$i++;
last LINE if($i==32);
#when the 32 line comes it exit the inner foreach loop and the $line32 contains the value of the 32 line in the text file and you can push it into the @array
}
@userii=push(@userii,$line32);
}
each time the value of $line32 is replaced by the value of $line.As soon as the $i==31 (its $i==31 instead of $i==32)we are coming out of inner foreach loop and before that $line32 is assigned the value of $line and we are pushing the value in to the array @userii..
the outer foreach loop takes the next file and does the same.
with the foreach outer loop we can push 32nd line of all the files in to the @userii
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.