develooper Front page | perl.perl5.porters | Postings from April 2007

Re: got Smack(ed) lately?

Thread Previous | Thread Next
From:
demerphq
Date:
April 18, 2007 01:58
Subject:
Re: got Smack(ed) lately?
Message ID:
9b18b3110704180158w27f5b633rdb0913397088edb@mail.gmail.com
On 4/18/07, Tom Christiansen <tchrist@perl.com> wrote:
> =for your consideration,
>
> The surrounding module, Smack.pm, runs perfectly well, as demonstrated by
>
>     % perl -MSmack -e 'smack && snarf && print "hurray!\n" '
>
> after clipping this message body and placing it in the obviously-named
> file: the expected "hurray!" is indeed correctly emitted.  But it is
> a false cheer, for this innocent module nevertheless has a bug or two
> lurking in it.
>
> Can you* see the problem?  If so, is it really glaringly obvious to
> everyone but me?  Has awareness of this niggling nasty passed into
> general understanding?
>
> I don't think so, but could of course be wrong.  Yet even if I *am*
> mistaken (and so more of you will say "Duh, Tom!" than who will say
> "D'oh, Perl!"), what are the poor module writers realistically supposed
> to do about this? Must they retroactively insulate themselves from this
> strange-action-at-a-distance bug?  This vexing matter may well not
> even have existed back when they wrote their innocent module.
>
> Why must module writers understand this?  I really can't see how it's
> their fault.  Anything that forces everybody else all to go off and
> change their existing module code can't be a good thing.  I would argue
> therefore that the fault lies not in these modules, but elsewhere entirely--
> pragmatically speaking, that is.
>
> No?
>
> --tom
>
> =cut
>
> package Smack;
> use strict;
> use warnings;
>
> use Exporter;
> our @ISA = 'Exporter';
> our @EXPORT = qw(smack snarf);
>
> my $DEFNAME = "bindata";
> my $NULL = chr(my $bye = 0);
> my $RECSEP = "\xff" . $NULL;
>
> sub smack {
>     my $file = @_ ? shift : $DEFNAME;
>     open(BINDATA, "> :raw", $file) || die "Can't smack > $file: $!";
>     {
>         local $\ = $RECSEP;
>         print BINDATA "line one";
>         print BINDATA "line two";
>     }
>     close(BINDATA) || die "can't close $file: $!";
>     printf "%s is size %d (should be 20)\n" , $file, -s $file;
>     return 1;
> }
>
> sub snarf {
>     my $file = @_ ? shift : $DEFNAME;
>     open(BINDATA, "< :raw", $file) || die "Can't snarf < $file: $!";
>     local $/ = $RECSEP;
>     local $_;
>     while (<BINDATA>) {
>         chomp;
>         printf "line %d of %s: %s\n", $., $file, $_;
>     }
>     close BINDATA;
>     return 1;
> }
>
> 1;
> # * where you != Audrey
>

Ok, so whats the bug? Enquiring minds want to know.

Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About