That will get the 2nd, 3rd and 4th lines into $first, $second and
$third respectively. Because they are my variables, they will be
lost as soon as you exit the while loop.
--untested--
my($first,$second,$third);
while(<FILE>){
$first = <FILE>;
$second = <FILE>;
$third = <FILE>;
last;
}
--untested--
-or-
--untested--
my($first,$second,$third);
my $count = 1;
while(<FILE>){
$first = <FILE> if $count == 1;
$second = <FILE> if $count == 2;
$third = <FILE> if $count == 3;
last if $count == 4;
}
--untested--
-or-
--untested--
my($first,$second,$third);
while(<FILE>){
$first = <FILE> if $. == 1;
$second = <FILE> if $. == 2;
$third = <FILE> if $. == 3;
last if $. == 4;
}
--untested--
-or-
--untested--
my @lines = <FILE>;
#access each ine as an element of the array
--untested--
-or-
use one of the _many_ Perl modules relating to files.
This question is a bit like "How do I print a formated line?". The
accepted/first method is to use 'printf'. However, depending on what
the end result is supposed to be and what else needs to be done and
how the output is _supposed_ to look, you could use 'format'. Or, you
could use 'sprintf' to format the string first, then use'print' to
print the line (now containing the formated string).
Try writing out what you want to do on paper _first_. The answer
_may_ just pop off the page at you.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL.
http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Whistler's Law: You never know who is right, but you always know
who is in charge.