in reply to a few basic questions

how do you print one line then get out of the loop and go back to it later and print the second line, what i mean is how do print line 1 from file a and then print line 1 of file b and then print line 2 file a and then line2 file b and so on.

Replies are listed 'Best First'.
Re: ??? how to print only one line
by IraTarball (Monk) on Aug 23, 2001 at 20:56 UTC
    This sounds like a job for the evil 'goto'...
    use strict; use warnings; open (T1, "t1") or die; my $line; my $flag = 1; my $counter; DATA: while (<DATA>) { print; goto T1; } T1: while (<T1>) { print; goto DATA; } __END__ file1 file1 file1 file1
    This prints...
    file1 file2 file1 file2 file1 file2 file1 file2 file2 file3, kidding... file2

    Ira,

    "So... What do all these little arrows mean?"
    ~unknown

Re: ??? how to print only one line
by CheeseLord (Deacon) on Aug 23, 2001 at 22:21 UTC

    In the spirit of TMTOWTDITDUG, here's my idea:

    #!/usr/bin/perl -w use strict; my ($fh1, $fh2); open $fh1, "file1.dat" or die "I no read file 1.\n"; open $fh2, "file2.dat" or die "I no read file 2.\n"; my $mainfh = $fh1; while (<$mainfh>) { print; $mainfh = ($mainfh == $fh1) ? $fh2 : $fh1; }
    file1.dat:
    I'm sure this
    file2.dat:
    pretty that works.
    And finally, output:
    I'm pretty sure that this works.

    His Royal Cheeziness