Greg Bacon <[EMAIL PROTECTED]> writes:

> Yesterday, I saw an interesting related exercise.  Write a program that
> reads the lines from a file and outputs the middle line.  The kicker is
> that you can't use arrays.  (Note that there's a little ambiguity with
> respect to the definition of "middle line" when the number of lines in
> the file is even or when there is only one line.  Just pick a reasonable
> definition and get to work.)

*SPOILER*
Here's a solution (that only works for files...)
*SPOILER*

    #!/usr/local/bin/perl -w
    # Print middle line of file(s)
    use strict;
    open F,$ARGV[0] or die;
    open G,$ARGV[0] or die;
    my $l;
    1 while (defined(<F>) && defined($l=<G>) && defined(<F>));
    print $l;

[...]

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | [EMAIL PROTECTED]
Compugen Ltd.          |   +++ THIS SPACE TO LET +++    \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658117 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels

Reply via email to