List Info

Thread: got Smack(ed) lately?




got Smack(ed) lately?
user name
2007-04-17 21:20:10
Re: got Smack(ed) lately?
user name
2007-04-18 01:19:09
On 4/17/07, Tom Christiansen <tchristperl.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 wish I could spot the problem. I can't. What is it?

I don't like that it exports things by default. I don't see
why you're
using a global filehandle instead of a lexical one. You
aren't
checking for success on your two writes (though I admit it
probably
wouldn't matter til the close()).

You're handling $/, $, and $_ sanely. You're ensuring that
you're
writing "bytes" to the files even under the
possible effect of the -C
runtime parameter.

So... I suppose you're not checking for an error during your
readline
loop over BINDATA. Surely that's not it. I've only ever seen
one
person attempt to check for errors from that.

Josh

Re: got Smack(ed) lately?
user name
2007-04-18 01:52:45
On Tue, April 17, 2007 11:19 pm, Joshua ben Jore wrote:
> You're handling $/, $, and $_ sanely.

Nope, should be local *_ or (better) my $_ or don't use $_
at all.




Re: got Smack(ed) lately?
user name
2007-04-18 03:58:20
On 4/18/07, Tom Christiansen <tchristperl.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: %sn", $.,
$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/"

Re: got Smack(ed) lately?
user name
2007-04-18 07:14:13
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Moin,

On Wednesday 18 April 2007 02:20:10 Tom Christiansen 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.

Why must your message readers understand this? I really
can't see how it's 
their failt.  Anything that forces everybody else all to go
off and change 
their existing..er sorry you lost me already.

Could you proviede please a concise summary on what the
problem actually is?

All the best,

Tels

- -- 
 Signed on Wed Apr 18 12:13:03 2007 with key 0x93B84C15.
 Get one of my photo posters: http://bloodgate.com/pos
ters
 PGP key on http://bloodgate.com/te
ls.asc or per email.

 "Q: What do you get when you cross an insomniac, an
agnostic, and a
 dyslexic?
 A: Someone who stays up all night wondering if there is a
 Dog."

  -- Groucho Marx
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iQEVAwUBRiYLlXcLPEOTuEwVAQIuFAf9E/3HVbZCDKmu90uev0/oDapkWDlK
FFrN
x1oa92mvYYSrOJu+bpqBIsg2hCy/hRBRedbfsNeoqM5+uQ5nxhsa7u8AdBtJ
vn9N
1WnVnGqjAVJqfmkXnLQnmh81Yi2J4SowoV4+OLMMJelcVuZ7gD2kZ5ZYJwQQ
Gtrs
dZ9yjnK1ycn4M77B4H/qXhydzjcEcSPMa4hKwsCL624XDMaj7ZIOb/Sjw+qM
9caO
PUe2JHj9RuiamhLO+U84qojt5iGM9PYjh9EcIUFuaBJXqspSBJG4VJ2RYqQd
sid/
gF6bSUDVKMd7krleLwch09SQOcjPXGNARbGgPlqDuWTlc3O05v2GVA==
=x+iI
-----END PGP SIGNATURE-----

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )