On Thu, Aug 23, 2001 at 05:28:42PM -0600, Gary Luther wrote:
> I have a file that has paired lines, in other words I need to process them kinda 
>like one line.
> 
> Let me 'splain.
> 
> I read a file into the array @rename
> 
> foreach $lines (@rename) {
>   do a bunch of stuff here
>   now I need to read the next line to get some info
>   that needs to be processed with the first line info
>   I want to be able to do something like???
>   $line2=<@rename>;
>   do some stuff on $line2
>   write out some stuff
> }

It'd be easier to accomplish this without using an intermediary array.

    while (defined($line1 = <FILE>)) {
        my $line2 = <FILE>;
        ...
    }


Otherwise, there are various solutions to your problem.

If you don't mind being destructive:

    while (my($line1, $line2) = splice(@rename, 0, 2)) {
        ...
    }


Destructive and possibly a little more readable:

    while (@rename) {
        my($line1, $line2) = (shift(@rename), shift(@rename));
        ...
    }


Destructive, readable, and possibly faster:

    @rename = reverse(@rename);
    while (@rename) {
        my($line1, $line2) = (pop(@rename), pop(@rename));
        ...
    }


Non-destructive for loop:

    for (my $i = 0; $i < @rename; $i += 2) {
        my($line1, $line2) = ($rename[$i], $rename[$i + 1]);
        ...
    }


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to