[22382] in Perl-Users-Digest
Perl-Users Digest, Issue: 4603 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 21 18:11:36 2003
Date: Fri, 21 Feb 2003 15:10:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 21 Feb 2003 Volume: 10 Number: 4603
Today's topics:
Re: Religious question: commenting <cwilbur@mithril.chromatico.net>
Re: Religious question: commenting (Tony L. Svanstrom)
Re: Religious question: commenting <mr@sandman.net>
Re: Religious question: commenting <mr@sandman.net>
Re: Religious question: commenting <mr@sandman.net>
Re: Religious question: commenting (Anno Siegel)
setting permissions on my server for cgi <cpb6043@osfmail.rit.edu>
Re: Switch order of sprintf conversions <mgjv@tradingpost.com.au>
Re: Switch order of sprintf conversions <wuerz@yahoo.com>
Re: Switch order of sprintf conversions <noreply@gunnar.cc>
Re: sysread and length <goldbb2@earthlink.net>
Re: sysread and length <mgjv@tradingpost.com.au>
Re: use DBI; <abigail@abigail.nl>
Re: windows based text editor? <ellem52@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 Feb 2003 20:30:22 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Religious question: commenting
Message-Id: <87wujt754t.fsf@mithril.chromatico.net>
>>>>> "S" == Sandman <mr@sandman.net> writes:
S> It's not that hard. How do you comment stuff?
It falls into a few categories for me:
* "This is ordinarily a stupid thing to do, but I did it in this case
because...."
Much of the code I write and maintain involves doing fairly mundane
things like connecting to databases. My fellow programmers work
with a variety of databases, and so in the case where I have to put
in an explicit workaround for a MySQL limitation, I include a
comment which mentions why I'm not using a subselect (for instance).
* "This is what we expect to see from the thing we're interacting
with."
I've written a fair bit of glue code in Perl, and I rarely have full
control over the things I interact with. So every time I need to
pick out a piece of data, or I expect data in a particular format, I
put comments in to that effect. The maintenance programmer may be
looking at my code under pressure, and trying to figure out where
things broke.
* "This next bit has convoluted data structures. Here's something to
watch out for. You might want to draw a diagram."
* "I'm going to do something for the sake of efficiency that I
probably won't understand myself when I look at it myself next week;
here's a summary of what it does."
There's a theme here. Comments are for the maintainer. My default
assumption is that anyone looking at my code is familiar with the
Camel book, and if they find an unfamiliar operator or function in my
code, they can look it up and see what it does. My end goal is not to
teach someone to program based on my scripts, but to communicate with
the maintainer of the code about how and why I did certain things.
Charlton
------------------------------
Date: Fri, 21 Feb 2003 21:50:04 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Religious question: commenting
Message-Id: <1fqr5wk.j8gy3xpnc4m3N%tony@svanstrom.com>
Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote:
> Comments are for the maintainer.
For many of us we are the maintainer, which makes it very important for
us to adopt a style of coding which will remain more or less the same
over time (which in turn makes it important for us to know our tools as
well as possible).
The thinking behind that is pretty simple, if you end up with a problem
with your own code you can almost always guess where what code is and
what it might look like; even if there are no/few comments.
Which brings us back to why it's ok that people commented on his code
and not only on the style of commenting; the code is the ultimate
comment, sort of. =)
--
# Per scientiam ad libertatem! // Through knowledge towards freedom! #
# Genom kunskap mot frihet! =*= (c) 1999-2002 tony@svanstrom.com =*= #
perl -e'print$_{$_} for sort%_=`lynx -source svanstrom.com/t`'
------------------------------
Date: Fri, 21 Feb 2003 23:10:17 +0100
From: Sandman <mr@sandman.net>
Subject: Re: Religious question: commenting
Message-Id: <mr-452AA6.23101721022003@news.fu-berlin.de>
In article <87wujt754t.fsf@mithril.chromatico.net>,
Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote:
> >>>>> "S" == Sandman <mr@sandman.net> writes:
>
> S> It's not that hard. How do you comment stuff?
>
> It falls into a few categories for me:
>
> * "This is ordinarily a stupid thing to do, but I did it in this case
> because...."
>
> Much of the code I write and maintain involves doing fairly mundane
> things like connecting to databases. My fellow programmers work
> with a variety of databases, and so in the case where I have to put
> in an explicit workaround for a MySQL limitation, I include a
> comment which mentions why I'm not using a subselect (for instance).
>
> * "This is what we expect to see from the thing we're interacting
> with."
>
> I've written a fair bit of glue code in Perl, and I rarely have full
> control over the things I interact with. So every time I need to
> pick out a piece of data, or I expect data in a particular format, I
> put comments in to that effect. The maintenance programmer may be
> looking at my code under pressure, and trying to figure out where
> things broke.
>
> * "This next bit has convoluted data structures. Here's something to
> watch out for. You might want to draw a diagram."
>
> * "I'm going to do something for the sake of efficiency that I
> probably won't understand myself when I look at it myself next week;
> here's a summary of what it does."
>
> There's a theme here. Comments are for the maintainer. My default
> assumption is that anyone looking at my code is familiar with the
> Camel book, and if they find an unfamiliar operator or function in my
> code, they can look it up and see what it does. My end goal is not to
> teach someone to program based on my scripts, but to communicate with
> the maintainer of the code about how and why I did certain things.
Thanks for your comments!
It seems you and I comment somewhat for the same reasons. :)
--
Sandman[.net]
------------------------------
Date: Fri, 21 Feb 2003 23:11:55 +0100
From: Sandman <mr@sandman.net>
Subject: Re: Religious question: commenting
Message-Id: <mr-1DBEE1.23115521022003@news.fu-berlin.de>
In article <b35fta$7ch$04$1@news.t-online.com>, Richard Voss <erutiurf@web.de>
wrote:
> > I asked the same question in the PHP group, and those guys all came back
> > with some examples on how they comment code. And while there were some guy
> > there aswell that focused on the code in the example instead, most of them
> > understodd what I wwas asking and answered accordingly.
>
> People in PHP groups are used to seeing ugly code, most of them write just
> such crap.
That's a particularly narrow-sighted thing to say.
--
Sandman[.net]
------------------------------
Date: Fri, 21 Feb 2003 23:16:00 +0100
From: Sandman <mr@sandman.net>
Subject: Re: Religious question: commenting
Message-Id: <mr-B83C81.23160021022003@news.fu-berlin.de>
In article <b35o83$jvt$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > > Or - to use the picture/caption relevance; It doesn't matter if the
> > > caption says 'George W. Bush' when it's a picture of Saddam Hussein.
> > > It's just wrong.
> >
> > So it would be impossible for you to use that captioning and that picture
> > to show me how you generally place captions? Odd.
>
> You appear to claim this thread as some virtual classroom, and for yourself
> the role of a teacher. Welcome to Usenet. We are going to comment on any
> aspects of your posts that strike our fancy.
You are free to post whatever you feel like. My intentions was to discuss
comments, and I felt I should try to direct the discussion back to that when I
noticed that some people were more interested in talking about coding only.
They, and you, are free to do so of course, and I can't moderate you in any
way. But I won't participate in such discussions however.
--
Sandman[.net]
------------------------------
Date: 21 Feb 2003 22:43:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Religious question: commenting
Message-Id: <b36a1r$jqh$1@mamenchi.zrz.TU-Berlin.DE>
Tony L. Svanstrom <tony@svanstrom.com> wrote in comp.lang.perl.misc:
> Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote:
>
> > Comments are for the maintainer.
>
> For many of us we are the maintainer, which makes it very important for
> us to adopt a style of coding which will remain more or less the same
> over time (which in turn makes it important for us to know our tools as
> well as possible).
>
> The thinking behind that is pretty simple, if you end up with a problem
> with your own code you can almost always guess where what code is and
> what it might look like; even if there are no/few comments.
>
> Which brings us back to why it's ok that people commented on his code
> and not only on the style of commenting; the code is the ultimate
> comment, sort of. =)
In any case comments are only one tool in making code understandable.
Asking people to restrict the discussion to only one aspect is silly.
Good naming, consistent conventions and clearly written code go a long
way. Using comments to explain what should be coded more clearly
only patches things over. When a bit of code needs an explanation, the
first attempt should be to re-write it so that it doesn't. Only if that
doesn't work, consider commenting it.
One reason why comment-writing is unpopular among programmers is that
it is hard to do right. It requires you to put yourself in the place
of someone who doesn't know what you're up to and to forget "for the
moment" all the intricacies of the code you're struggling with. The
mental effort of viewing your work from outside is disruptive, but if
it isn't made, the resulting comment is likely to be unhelpful. It is
far easier to just write down what goes through your head at the moment,
so this happens a lot, but (like in Usenet subject lines), the result is
mostly unsatisfactory. We have all puzzled over comments that look
like radio messages from Mars.
A good program doesn't need no steenkin comments!
Anno
--
perl -e'$_=shift().".pm";s|::|/|g;require;exec"view",$INC{ $_}' File::Find
------------------------------
Date: Fri, 21 Feb 2003 16:26:05 -0500
From: "chris" <cpb6043@osfmail.rit.edu>
Subject: setting permissions on my server for cgi
Message-Id: <3e5698e3@news.isc.rit.edu>
i am having a few problems getting cgi scripts to work on my server.
my directory is http://www.rit.edu/~cpb6043/cgi/
as you can see, test.cgi works and test2.cgi does not.
i talked with my local network administrators, and they got it to work. they
said (using telnet) to set the permissions for each file to 755
(read,execute) and the folder to the same thing (i think). i tried this and
it still doesn't work. the contents of test.cgi is:
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "HELLO";
i have checked to make sure that the path to perl is right. it is.
i have checked to make sure that this is the proper way to send the header.
it is.
i do not know why this doesn't work.
anyone?
all help would be appreciated.
thanks,
chris.
------------------------------
Date: Sat, 22 Feb 2003 08:33:03 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Switch order of sprintf conversions
Message-Id: <slrnb5d6of.2fm.mgjv@martien.heliotrope.home>
On Fri, 21 Feb 2003 18:56:13 GMT,
Jay Tilton <tiltonj@erols.com> wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>: Jay Tilton wrote:
>: > : C program, $string could have been assigned (the equivalent of) "There
>: > : Is %2$s Than %1$s Way To Do It".
>: > :
>: > : Is there a way in Perl to achieve the same thing?
>: >
>: > Yup.
>: > Do the same thing you would in C.
>:
>: Can you please expand on that, Jay? I have tried it, but when using the
>: above string, the sprintf function just returns:
>:
>: "There Is %2 Than %1 Way To Do It"
>:
>: It would be much appreciated if you could give me some additional guidance.
>
> Sorry for the content-free reply there. This is evidently a new
> ability of sprintf, introduced with Perl 5.8.
>
> printf '%3$s %2$s %1$s', qw/one two three/;
>
> outputs:
>
> three two one
Just to avoid some more confusion for people not on Unix systems:
that format specification to printf and friends is not C. It is not
part of the C standard, but of the SUS specification, and therefore can
only be guaranteed to be available on Unix systems, and systems that use
compilers and libraries that incorporate some or all of the SUS spec
(like the GNU compiler and C library).
If you use gettext, then most likely you are on a system that implements
these conversion specifiers, but don't count on them otherwise, and
don't use them if you need to write portable code (or make sure you have
the appropriate require VERSION somewhere).
Martien
--
|
Martien Verbruggen | life ain't fair, but the root password helps.
| -- BOFH
|
------------------------------
Date: 21 Feb 2003 16:55:45 -0500
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: Switch order of sprintf conversions
Message-Id: <m3y9495me6.fsf@karrooite.njitdm.campus.njit.edu>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Josef Drexler <nospam1202@joesbox.cjb.net> wrote in comp.lang.perl.misc:
> > Anno Siegel wrote:
> > > I'm amazed the need to rearrange arguments hasn't come up earlier.
As a matter of fact, it has - in de.clpm. See, e.g.
<jktao9.8sn.ln@al.brain.de> and the ensuing thread (in German).
> > That's a good idea, but I think it would be more useful to have this
> > permutation specified as part of the format string, because it will be
> > necessary in only some instances, and a different permutation may be
> > necessary for each string.
> >
> > It would probably be worthwhile to write a substitute for sprintf that
> > supports the "%2$d" notation of the C sprintf.
As a first stab at it, I came up with
#!perl -w
use strict;
sub fmt {
my $fmt = shift;
my @fmts;
my $i=0;
while ($fmt =~ s/(\%\d?\$?\d?\.?\d?[%csduoxefgXEGbpn])/\$fmts[$i]/) {
push @fmts, $1; $i++;
}
@fmts = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, s/\%(\d*)\$/\%/?$1:0 ] } @fmts;
$fmt =~ s/\$fmts\[(\d+)\]/$fmts[$1]/g;
$fmt =~ s/\\n/\n/g; # etc...
$fmt
}
printf "%.3f + %s = %g\n", 1.234567, 'foo', 42*1_000_000;
printf fmt ('%2$.3f + %1$s = %g\n'), 1.234567, 'foo', 42*1_000_000;
printf fmt ('%2$.3f + %3$s = %1g\n'), 1.234567, 'foo', 42*1_000_000; # oops!
__END__
That obviously doesn't allow for variable interpolation in the format
string; it is also rather halfheartedly tested otherwise. But it's a start.
> > Putting that in a module would be very useful. You'd probably have to
> > write a parser for the format string though instead of using just a simple
> > regex...
>
> Quite. Having to parse a sprintf format made me refrain from suggesting
> such a thing. For the moment it looks easier to allow for an optional
> permutation to be stored along with each format.
Indeed.
--
$_="\n,rekcah egnufeB rehtona tsuJ";#v1<?>g\:pv-<5<
s s\S+(?:B)sunpack'u',q q$;')E4qsee;#>60#^<(v!<)g6<
print scalar reverse,$@ unless m,[+;#]55,;m:_,:#^1<
------------------------------
Date: Fri, 21 Feb 2003 22:16:47 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Switch order of sprintf conversions
Message-Id: <jzx5a.11648$FF4.632268@newsb.telia.net>
Anno Siegel wrote:
> To be completely general, you may want to allow any permutation, not
> only reversal. You could store a list of small integers in a hash
> and use a list slice to do the actual rearrangement:
>
> if ( exists $permute{$lang} ) {
> printf( $string, ($one, $more)[ @{ $permute{ $lang}}]);
> }
Josef Drexler wrote:
> That's a good idea, but I think it would be more useful to have this
> permutation specified as part of the format string, because it will be
> necessary in only some instances, and a different permutation may be
> necessary for each string.
>
> It would probably be worthwhile to write a substitute for sprintf that
> supports the "%2$d" notation of the C sprintf.
>
> [snip]
>
> You'd probably have to write a parser for the format string though
> instead of using just a simple regex...
Hmm.. I have to say that the idea with replacing sprintf with a
'self-made' function, for those cases where there are more than one
argument, is tempting. As regards parsing, I don't think it will mean
any bigger problems, since the strings are short.
Jay Tilton wrote:
> This is evidently a new ability of sprintf, introduced with Perl 5.8.
>
> printf '%3$s %2$s %1$s', qw/one two three/;
>
> outputs:
>
> three two one
Aha, that explains why it didn't work for me (on Perl 5.6).
Nevertheless, I think that the newly introduced ability, to interpret
the previously C specific notation, is another good reason to go for
Josef's idea. Then, in five years or so (I'm anxious about portability),
I can require Perl 5.8 and remove my 'self-made' sprintf function. ;-)
Thanks, guys, for your input in this thread. You have indeed helped me
make a well-founded decision.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 21 Feb 2003 16:06:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sysread and length
Message-Id: <3E5694D2.A14D38FC@earthlink.net>
"George C. Demetros" wrote:
>
> Hi.
>
> How does one determine the right LENGTH to specify on sysread:
>
> sysread(FILEHANDLE, SCALAR, LENGTH, OFFSET)
>
> I have file handles that are a socket, a fifo file, and file
> descriptor 3 handle on a pipe. The data I will be reading can vary in
> length from a few bytes to a whole lot of bytes. Is there an optimum
> length to select for each type of handle if the data is not fixed in
> length?
my $optimum_size = (stat FILEHANDLE)[11];
This may return "" on some operating systems, so make sure you || it
with some sensible default, such as:
my $optimum_size = (stat FILEHANDLE)[11] || 4096;
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Sat, 22 Feb 2003 08:48:18 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: sysread and length
Message-Id: <slrnb5d7l1.2fm.mgjv@martien.heliotrope.home>
On Fri, 21 Feb 2003 17:31:30 GMT,
David <perl-dvd@darklaser.com> wrote:
> "George C. Demetros" <demetros@edamail.fishkill.ibm.com> wrote in
> message news:3E4D38C6.801F774F@edamail.fishkill.ibm.com...
>> Hi.
>>
>> How does one determine the right LENGTH to specify on sysread:
>>
>> sysread(FILEHANDLE, SCALAR, LENGTH, OFFSET)
>>
>> I have file handles that are a socket, a fifo file, and file
>> descriptor 3 handle on a pipe. The data I will be reading can vary
>> in length from a few bytes to a whole lot of bytes. Is there an
>> optimum length to select for each type of handle if the data is not
>> fixed in length?
>
> I have always just used the whole length with read:
>
> read(STDIN, $input, $ENV{'CONTENT_LENGTH'}, 0);
And what if the environment doesn't provide an environment variable with
the name "CONTENT_LENGTH"? Most environments I program in don't. I am
pretty certain, given the rest of the OP's description of the problem,
that that environment variable, even if it is present, is going to be of
any help.
> With this, I have read in as much as 30 MB of data in one chunk and
> never had a problem.
If you indeed want all data in $input, you might as well read it all in
in one go. Determining what that one go is, depends on what you're
reading from, and whether the information about how much total data is
going to need to be read, is available.
Since the OP actually asked about sysread, and not read, I'll assume
that the OP had a good reason for that, I suspect that a smallish buffer
(8k, 16k, 32k) is probably ok. If "a whole lot of bytes" is less than 1
k, use a buffer of 1k. I'd say pick a size, and play with it a bit (and
use real-life data sizes and communications).
Martien
--
|
Martien Verbruggen | Unix is user friendly. It's just selective
| about its friends.
|
------------------------------
Date: 21 Feb 2003 22:37:43 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: use DBI;
Message-Id: <slrnb5dahn.haa.abigail@alexandra.abigail.nl>
Helgi Briem (helgi@decode.is) wrote on MMMCDLXI September MCMXCIII in
<URL:news:3e560d61.1208363965@news.cis.dfn.de>:
'' On 20 Feb 2003 23:54:29 GMT, Abigail <abigail@abigail.nl>
'' wrote:
''
'' >Helgi Briem (helgi@decode.is) wrote on MMMCDLX September MCMXCIII in
''
'' >&& So you would approve if people stuck random things
'' >&& in their code here and there that didn't do anything?
'' >
'' >No, but what does that have to do with 'exit'? I haven't encountered
'' >a Perl in which 'exit' doesn't do anything.
''
'' What does it do here that wouldn't have happened
'' anyway?
Which is something else entirely. Big fucking deal, as I said before.
People write parens where they aren't doing anything all the time.
People use $_ where they could left them off.
exit(0) *DOES* do something. And it isn't cargo cult either.
Abigail
--
perl -Mstrict -we '$_ = "goto E.print chop;\n=rekcaH lreP rehtona tsuJ";E1:eval'
------------------------------
Date: Fri, 21 Feb 2003 14:16:58 -0500
From: LM <ellem52@mail.com>
Subject: Re: windows based text editor?
Message-Id: <0nuc5voa1bqh78b98685trtilrkol6su1b@4ax.com>
On Mon, 10 Feb 2003 20:45:35 +0100, "Alan J. Flavell"
<flavell@mail.cern.ch> wrote:
>On Feb 10, Nataku extruded TOFU onto the eternal parchment:
>
>> emacs ...
>
>Ah yes, the "answer to life, the universe, and everything"
>wasn't really 42, but "emacs".
>
>e = 5
>m = 13
>a = 1
>c = 3
>s = 19
> --
> 41 ???
> --
Ahh but you have forgotten the invisible/silent 'a' in
e = 5
m =13
a = 1
a = 1
c = 3
s = 19
_____
42
--
There's more than one way to do it, but only some of them work
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4603
***************************************