in reply to Spot the Bug

use strict; use warnings; # my $file = shift || die "No file, dummy!"; # open FH, "<", $file or die "Could not open ($file) for reading: $ +!"; local $/ = "\n.\n"; while (defined (my $record = <DATA>)) { chomp $record; print $record; # <STDIN>; } __DATA__ sdjh sfhg srig srgsrigh . . . asdigf wsergh

This gives:

sdjh sfhg srig srgsrigh.asdigf wsergh

A . was left there unremoved, if that's the bug you are looking for (As it cannot handle empty record.)

Replies are listed 'Best First'.
Re^2: Spot the Bug
by Mr. Muskrat (Canon) on Sep 09, 2005 at 02:02 UTC
    For enlightenment, uncomment the code that you commented out one line at a time until the bug rears its ugly head.

      The other thing is that <STDIN>. It does not return in the normal way, which is expected base on the code, as line break has been reset to "\n.\n". But you can easily get around by entering "\n.\n" (<Enter>.<Enter>) to continue and inspect the next record.

      Any way, my first reply still reveals a bug, if the program is required to handle empty record.

Re^2: Spot the Bug
by Ovid (Cardinal) on Sep 09, 2005 at 02:13 UTC

    That would be a bug if my data were structured that way, but they were in a guaranteed format. Nice idea, though.

    Cheers,
    Ovid

    New address of my CGI Course.