my $fh = new IO::File; open($fh, "file") or die "file: $!"; while (<$fh>){print}; eval { ... }; warn $@ if $@; #a bit like END{ }; # but on any scale. |
fh = open('foo.txt') for line in fh: print line try: #something except IOError, e: print "got IOError", e except MemoryError: raise try: #something finally: #cleanup. |