[22371] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4592 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 20 09:11:16 2003

Date: Thu, 20 Feb 2003 06:10:12 -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           Thu, 20 Feb 2003     Volume: 10 Number: 4592

Today's topics:
    Re: Religious question: commenting (Helgi Briem)
    Re: Religious question: commenting (Anno Siegel)
    Re: Religious question: commenting (C Marshall)
    Re: Report physical RAM of a remote PC <ubl@schaffhausen.de>
    Re: Report physical RAM of a remote PC <go@way.com>
    Re: Report physical RAM of a remote PC <go@way.com>
    Re: Unsuccesful "Print" <bart.lateur@pandora.be>
    Re: use DBI; (Helgi Briem)
    Re: use DBI; <tassilo.parseval@post.rwth-aachen.de>
    Re: using tar.bz2 <dont@want.spam>
    Re: Variables from 'require' not initialized nobull@mail.com
    Re: When is perl6 expected to be available? <mgjv@tradingpost.com.au>
    Re: When is perl6 expected to be available? <tore@aursand.no>
    Re: When is perl6 expected to be available? (Tad McClellan)
    Re: When is perl6 expected to be available? <REMOVEsdnCAPS@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 20 Feb 2003 10:15:45 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Religious question: commenting
Message-Id: <3e54aa33.1117431361@news.cis.dfn.de>

On Thu, 20 Feb 2003 07:44:55 +0100, Sandman <mr@sandman.net>
wrote:

>I strongly suggest you stop focusing on the code, and start talking 
>about  commenting. This is a useless discussion. Sorry. I 
>suppose this is what I get for bringing up a topic as religious as 
>this.

I don't think he should.  Every comment Tassilo has made
has been spot-on.  It has taught me things I was
better off knowing.

You should focus more on the code and less on the 
commenting.

-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: 20 Feb 2003 10:37:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Religious question: commenting
Message-Id: <b32b4o$r0p$1@mamenchi.zrz.TU-Berlin.DE>

Sandman  <mr@sandman.net> wrote in comp.lang.perl.misc:
> In article <b313rc$9la$1@nets3.rz.RWTH-Aachen.DE>,
>  "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote:
> 
> > > if ($in{who}){ $who = $in{who}; }           # default is $in{who}
> > > if ($in{name}){ $who = $in{name}; }         # but $in{name} overwrites
> > > if ($in{person}){ $who = $in{person}; }     # as does $in{person}
> > > 
> > > These comments are redundant, since the code clearly shows that this
> > > is what happens. But when these three lines are found in the middle of
> > > a lengthy script, another reader might ask "Why is he doing this? Is
> > > this his intention?  All it does is overwrite the variable..." - That
> > > reader sees, by reading the comment, that that is indeed my intention.
> > 
> > The above code should have never been written. A good example how clear
> > code can make comments obsolete. Typically the above would change to:
> > 
> >     $who ||= $in{person} || $in{name} || $in{who};
> > 
> > After all, this is what the ||= and || operators are for. Only a little
> > familiarity with those is needed to understand immediately what's going
> > on whereas I find the above if-chain harder to follow (the comment wont
> > necessarily turn it into nice code).
> 
> Sigh. It was an example. Stop focusing on the -code-. Or are you claiming that 

It is impossible to discuss comments without looking at their relationship
to the code.  It's like discussing the caption of a picture without
looking at the picture.

> the above example is totally invalid, and it doesn't illustrate a situation 
> where redundant commenting would be useful?

Redundant comments are never useful.  In your example, what deserves
commenting is (probably) that there are three possible sources for
$who and their precedence.  This would be a collective comment pertaining
to all three lines.  Explaining the obvious action of each line to
the reader is not directly useful.  Writing redundant comments to
tell the reader that you thought about the code and really mean what
it says is going to be unconvincing.

Changing the code to a standard idiom that doesn't need commenting
is a far better solution.

> > > Or what if I have a foreach() like this:
> > > 
> > > foreach (keys %fields){
> > >     print "$field{$_}<br>\n";
> > >     push @values, $_;                       # save for later in array
> > > }
> > > 
> > > The above @values array may only be used this one time in the entire
> > > program, but the comment illustrates how I've imagined that this
> > > information might come in handy, so I put it in an array. And people
> > > will know that I did so intentionally.
> > 
> > I strongly suggest you remove code that doesn't do anything.
> 
> I strongly suggest you stop focusing on the code, and start talking about 
> commenting. This is a useless discussion. Sorry. I suppose this is what I get 
> for bringing up a topic as religious as this.

In this case, the whole line should have been made a comment.  That way
readers *know* that the code in question doesn't do anything in the
current program.  As Tassilo has noted, the way you have done it sends
the reader on a chase for where @values is used again.

Again it's impossible to improve the comment and leave the code alone.
The question of commenting style is impossible to discuss without
also discussing coding style.

The best comments are those that aren't necessary because the code
is clear.

Anno


------------------------------

Date: 20 Feb 2003 05:45:30 -0800
From: c_j_marshall@hotmail.com (C Marshall)
Subject: Re: Religious question: commenting
Message-Id: <cb9c7b76.0302200545.6776ee89@posting.google.com>

"Tore Aursand" <tore@aursand.no> wrote in message news:<pan.2003.02.20.00.19.10.373097@aursand.no>...
> On Wed, 19 Feb 2003 16:08:30 -0600, Tad McClellan wrote:
> > Comments should say _why_ something is being done.
> 
> Oh?  My comments always say what _really_ should have happened. :)

hee hee


------------------------------

Date: Thu, 20 Feb 2003 10:40:36 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Report physical RAM of a remote PC
Message-Id: <b32b1q$er$1@news.dtag.de>

Iain Chalmers wrote:
> #!/usr/bin/perl -w
> use strict;
> 
> my $test;
> while(1){
>     $test.='X';
>     print "you have at least $_ bytes of ram available\n";
>     }
> -----------------------------------------------------------------

Obviously you mean:

my $test = "";
my $i = 0;
while(++$i){
     $test.='X';

     print "you have at least $i bytes of ram available\n";
}

cheers,
->malte



------------------------------

Date: Thu, 20 Feb 2003 12:32:03 +0000 (UTC)
From: "JohnShep" <go@way.com>
Subject: Re: Report physical RAM of a remote PC
Message-Id: <b32hs3$dkn$1@knossos.btinternet.com>


"SAPBasis2003" <sapbasis2003@netscape.net> wrote in message
news:3E5481FD.10600@netscape.net...
> How can I report the RAM of a remote PC?
> Does anybody have a sample code to do this?
> Thank you.

#!/usr/bin/perl -w
use CGI::Carp 'fatalsToBrowser';
print "Content-type: text/html\n\n<PRE>";
print system ("cat /proc/meminfo");

Caveat, it's cheap and nasty but should work on a Linux box.

JohnShep




------------------------------

Date: Thu, 20 Feb 2003 12:50:22 +0000 (UTC)
From: "JohnShep" <go@way.com>
Subject: Re: Report physical RAM of a remote PC
Message-Id: <b32iud$jqb$1@sparta.btinternet.com>

"JohnShep" <go@way.com> wrote in message
news:b32hs3$dkn$1@knossos.btinternet.com...
>
> "SAPBasis2003" <sapbasis2003@netscape.net> wrote in message
> news:3E5481FD.10600@netscape.net...
> > How can I report the RAM of a remote PC?
> > Does anybody have a sample code to do this?
> > Thank you.
>
> #!/usr/bin/perl -w
> use CGI::Carp 'fatalsToBrowser';
> print "Content-type: text/html\n\n<PRE>";
> print system ("cat /proc/meminfo");
  ^^^^
Ooops, print shouldn't be there, won't break it though.
JohnShep





------------------------------

Date: Thu, 20 Feb 2003 13:07:24 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Unsuccesful "Print"
Message-Id: <khk95vc8m7d9bjs74l71d06cirm9v9cl69@4ax.com>

Mikey wrote:

>If I do this, I get errors:
>
>Global symbol "$opt_a" requires explicit package name at ./perlfile
>Global symbol "$opt_h" requires explicit package name at ./perlfile
>
>It's getting worse, why is that?

If that is worse, then don't use individual scalars: use one hash. That
may just as well be a lexical.

	use Getopt::Std;
	my %opt;
	getopts('ha:', \%opt);
	if($opt{h}) {
	   print "-h selected\n";
	}
	if(defined $opt{a}) {
	   print "-a selected, value '$opt{a}'\n";
	}

-- 
	Bart.


------------------------------

Date: Thu, 20 Feb 2003 09:57:12 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: use DBI;
Message-Id: <3e54a44e.1115921720@news.cis.dfn.de>

On 19 Feb 2003 19:52:59 GMT, Abigail <abigail@abigail.nl>
wrote:

>;;  Do you use exit(0) a lot?  And if so, what for?
>
>What is 'a lot'? I sometimes use 'exit' at a point where it would
>reach the end of the file anyway. And sometimes, even an 'exit 0'.
>Sometimes I don't. I do the same in shell scripts. Why? Just because
>something I feel like doing so.

So you would approve if people stuck random things
in their code here and there that didn't do anything?

my $foo = sin(rand (300)); 
undef $foo;

>I don't see anything wrong with that. Why are you all over that, 
>eager to slap it with a label 'Cargo Cult'?

Because I have never seen it in code that the person
wrote himself from scratch, only in (old) code that people
got somewhere else.  Mostly Matt's scripts, come to
think of it.

Of course, it means that someone (Matt?) once put the 
original exit in there, so someone does (or did) use it.  

I was just wondering out loud, that's all.  Where does it 
come from?  Was it once needed for some reason?  Is it 
needed in C or some other language?  Because as far as I can

see, (I may very well be wrong), it is never needed or
particularly useful in Perl.  

As a convenient quasi-comment for "subroutine
declarations start here" it is not useful, but kinda
neat all the same.

It's no big deal to me, just a throwaway comment,
unconnected with the body of the post. An exit(0) if you 
like.
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: 20 Feb 2003 11:34:54 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: use DBI;
Message-Id: <b32egu$nt6$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Helgi Briem:

[ exit() ]
> I was just wondering out loud, that's all.  Where does it 
> come from?  Was it once needed for some reason?  Is it 
> needed in C or some other language?  

Yes, the background is C in fact. The prototype is:

    void exit(int status); /* from stdlib.h */

where additionally two constants EXIT_SUCCESS and EXIT_FAILURE can be
used. C does not know about default values if you leave off the argument
so there you always have to say 'exit(0)' (or 'exit(EXIT_SUCCESS' for
that matter) if you want to terminate the program with a succesful
value. The main() function in C likewise has a return value of 'int' so in
C you must be explicicit to indicate the exit status of your program.

Perl is not doing it much differently except that it assumes some
defaults when the programmer doesn't care about it. 

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Thu, 20 Feb 2003 08:28:55 +0000
From: Chris Lowth <dont@want.spam>
Subject: Re: using tar.bz2
Message-Id: <tt05a.212$J77.11275@newsfep2-win.server.ntli.net>

samphdauto wrote:

> Hello all
> 
> I am having hard time understanding what is going on with this..
> I got Perl source code then got a C compiler gcc-3.2.2.tar.bz2 to
> compile it then I got a ziping software bzip2-102-x86-win32 to unzip
> the compiler then I don't know how to use this bzip2-102-x86-win32
> thing.. it is not an *.exe .. I am working under W2K and my mind is
> not set up for open source and all those things yet. I got Programming
> Perl which seems to dive right into things with out much intro.
> 
> thanks
> 
> Sam

Building your own perl is not really a good place to start if you are new to 
opensource - doing it on windows particularly so!

The "activestate" distribution is pre-compiled and has free version. Start 
there, learn to walk and leave flying for a week or two.

You'll find it at..

http://www.activestate.com/Products/Download/Register.plex?id=ActivePerl

Good luck - enjoy!

Chris
-- 
My real e-mail address is
chris <at> lowth <dot> com


------------------------------

Date: 20 Feb 2003 00:23:39 -0800
From: nobull@mail.com
Subject: Re: Variables from 'require' not initialized
Message-Id: <4dafc536.0302200023.7d052600@posting.google.com>

Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov> wrote in message news:<3E53D944.9090402@larc.nasa.gov>...
> > The fact that lexically scoped variables are _lexically_ _scoped_.
> > 
> > When you declare a variable with my() the scope of the declaration is
> > from the end of the current statment to the end of the current lexical
> > scope.  i.e. until the first unmatched '}' in the _current_ source
> > file.
> >  
> > If you want a file included with requre to alter variable in the
> > calling environment you need to be using package scoped variables.
> > 
> > 
> 
> Ok, here's my first attempt at using package variables:
> 
> Script:
> ----------

>    require $inputfile;

> my $span = $parameters::span;


> Input:
> ----------

> package parameters;
> my ($rawfilename, $span, $outboard_chord, $grid_type, $velocity, 
> $aoa_degrees);

> $span = 10.0;           # Wingspan (inboard chord is 1.0000)

> 1;

> So what am I missing this time?

You are still declaring the variables as lexically scoped (but this
time in the other file).

You should change my() to our().  Or simply have 'no strict qw(vars)'
in the input file and don't declare at all.

BTW: our() doesn't strictly create a package variable, it declares a
lexically scoped alias for a package variable.

Note: you do not _need_ to put the parameters in a separate package
although some people think it is better to do so.  If you want to do
so then I would put the 'package parameters' directive in the block
containing the require() rather than rely on it being placed in all
input files.

I also note you have -T in the script.  If you are allowing the user
to provide a file that contains arbitrarty Perl to execute then this
completely negates any good that would come from tainting.  If you do
not totally trust the person who writes the input file then you should
process it with the rdo() method from the Safe module.


------------------------------

Date: Thu, 20 Feb 2003 21:48:18 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: When is perl6 expected to be available?
Message-Id: <slrnb59cji.rk9.mgjv@martien.heliotrope.home>

On 19 Feb 2003 23:43:52 -0800,
	Hiroki Horiuchi <hiroki@air.ne.jp> wrote:
> Hello folks.
> When is perl6 expected to be available?

There is no date for delivery on Perl 6. They're still defining the
language. Work is being done on the implementation as well, but it has
to follow the language design decisions, and they are far from settled
down.

More info at http://dev.perl.org/perl6/

I am surprised that you think you need to know if you don't know the
answer already :) What do you think Perl 6 is going to give you that you
don't already have?

Martien
-- 
                        | 
Martien Verbruggen      | Since light travels faster than sound, isn't
                        | that why some people appear bright until you
                        | hear them speak?


------------------------------

Date: Thu, 20 Feb 2003 12:49:17 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: When is perl6 expected to be available?
Message-Id: <pan.2003.02.20.11.48.52.336051@aursand.no>

On Wed, 19 Feb 2003 23:43:52 -0800, Hiroki Horiuchi wrote:
> When is perl6 expected to be available?

Not for a while yet.  This question is answered in Perl's FAQ, though;

  'perldoc -q perl6'

  "Perl6 is not scheduled for release yet, and Perl5 will still be
   supported for quite awhile after its release. Do not wait for
   Perl6 to do whatever you need to do."

Conclusion:  Don't wait for it.  Yet. :)


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/



------------------------------

Date: Thu, 20 Feb 2003 06:54:11 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: When is perl6 expected to be available?
Message-Id: <slrnb59jvj.3bs.tadmc@magna.augustmail.com>

Hiroki Horiuchi <hiroki@air.ne.jp> wrote:

> When is perl6 expected to be available?


Several years from now.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 20 Feb 2003 07:22:45 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: When is perl6 expected to be available?
Message-Id: <Xns9328553895408sdn.comcast@216.166.71.239>

hiroki@air.ne.jp (Hiroki Horiuchi) wrote in 
news:85c98cd5.0302192343.7f00ec4a@posting.google.com:

> Hello folks.
> When is perl6 expected to be available?
> Thanks in advance.
> 

Never, I hope.    ;-)

-- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;


------------------------------

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 4592
***************************************


home help back first fref pref prev next nref lref last post