in reply to Chew before you swallow

/me bows down on his knees and sacrifices a small stuffed animal on his st.larry shrine and prays for autochomping file handles.

Replies are listed 'Best First'.
Re^2: Chew before you swallow
by tadman (Prior) on Jun 28, 2002 at 22:17 UTC
    Sub-class IO::File and you've already got it. Should be a no-brainer.
    #!/usr/bin/perl -w package IO::File::AutoChomp; use base 'IO::File'; sub getline { my ($self) = @_; # Awkward, I know. return (map { chomp; $_ } $self->SUPER::getline())[0]; } sub getlines { my ($self) = @_; return map { chomp; $_ } $self->SUPER::getlines(); } package main; my $fh = IO::File::AutoChomp->new_from_fd(*DATA, "r") || die "Could no +t open DATA\n"; print join(",", $fh->getlines()); $fh->close(); __END__ The wily rat ate the last donut.