> : #!/usr/bin/perl -w > : > : $j++; > : > : while (<>) { > : $line{$.} = $_; > : delete $line{$j++} if ($. == 2 * $j); > : } > : > : print $line{$j}; > > A hash is an associative array and, thus, isn't kosher > for the problem as stated.
Lets remind ourselves of the problem: 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.) Associative array... looks like I don't get away with that one :o) I could do the large string thingy, with the regexps like others have done... or look again at the problem :- - Must read lines from a file - Must output middle line - Can't use arrays Thus, if we output everything we have outputted the middle line... simple huh? (although some *might* consider this cheating (understatement?)). Here's the script: #!/usr/bin/perl -p I think I win in both script and perl golf forms of the challenge :D Jonathan Paton __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com