in reply to Read each paragraph from a text file

Assuming the filename is "para.txt"... (spoiler follows)

# This code is intentionally "not the right way to do it", # and is just a demonstration of an alternative technique. print do{ local( $/, @ARGV ) = ( "", 'para.txt' ); (<>)[1,3] }

If you want to really learn how to work with files using Perl, you will really benefit by reading perlopentut: The tutorial on "open", perlfaq5: How can I read in a file by paragraphs?, perlvar: $/, and perldoc -f open: the documentation on "open" to gain a firm understanding of it all.

Oh, and if you choose to turn in my snippet (I wouldn't advise doing so, as I'm almost certain the professor had a more commonly used method in mind. My solution is not "the right way to do it"), be sure to also read perldata: Slices and perldoc -f do: The documentation for "do".

What you've asked is one of those things Perl is made to do with ease.


Dave