Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Off-topic Perl Question

Re: Off-topic Perl Question

From: Steven Lembark <lembark_at_wrkhors.com>
Date: Fri, 25 Jan 2002 07:43:07 -0800
Message-ID: <F001.003FB213.20020125072521@fatcity.com>

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 = $_;
    ...
}

> 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(<FILE_IN>)
> { 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: abiy.alemu_at_criltelecom.com
>
> 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: ListGuru_at_fatcity.com (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: lembark_at_wrkhors.com

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: ListGuru_at_fatcity.com (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).
Received on Fri Jan 25 2002 - 09:43:07 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US