Three methods: read newline delimeted two at a time, read the whole thing
and process it in pairs of lines or read twice the size of a fixed-length
line from columnar data:
while(<>)
{
my $line = $_ . <>;
...
}
or
my @linz = <>;
for( my $i = 0 ; $i < @linz ; $i += 2 )
{
my @twolinz = ( $linz[$i], $linz[$i+1] );
...
}
can be written more succinctly as:
my @linz = <>;
while( @linz )
{
my @twolinz = splice @linz, 0, 2;
...
}
or, if they are fixed length:
my $size = 2 * $sizeofaline;
$/ = \$size;
while(<>)
{
my $twolinz = $_;
...
}
-- ALEMU Abiy <[EMAIL PROTECTED]>
> I know that this is not the forum to ask perl questions. But is there
> some one who can help me on how to read two lines at a time using
> a Perl script
>
> My script looks like this :
>
> open(FILE_IN, "<$datafile") or die "Cannot open $datafile...\n";
>
> while()
> { chomp;
> @fields = split(/;/);
>
> print ("Processing line $. for emission...\n");
> PROMPT Processing $. for emission ...
>
> ($cField1, $cField2, $cField3) = @fields[0..2];
>
> ... and so on
>
> In this case, as you see, it takes only a line at a time and I would to
> consider couple of lines at a time.
>
> Is it possible to do it and how ?
>
> Please help.
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: ALEMU Abiy
> INET: [EMAIL PROTECTED]
>
> Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California-- Public Internet access / Mailing Lists
>
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
--
Steven Lembark 2930 W. Palmer
Workhorse Computing Chicago, IL 60647
+1 800 762 1582
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Steven Lembark
INET: [EMAIL PROTECTED]
Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).