[23898] in Perl-Users-Digest
Perl-Users Digest, Issue: 6100 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 9 14:06:03 2004
Date: Mon, 9 Feb 2004 11:05:07 -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 Mon, 9 Feb 2004 Volume: 10 Number: 6100
Today's topics:
Re: [WWW::Mechanize] how to 'click' on javascript:next <kha@rogers.com>
Re: [WWW::Mechanize] how to 'click' on javascript:next <usenet@morrow.me.uk>
Re: [WWW::Mechanize] how to 'click' on javascript:next <gregory@pharmag.pl>
Re: [WWW::Mechanize] how to 'click' on javascript:next <usenet@morrow.me.uk>
Re: CGI.pm & multipart <chatiman@free.fr>
Re: CGI.pm & multipart ctcgag@hotmail.com
Re: DBI::mysql column names as hash keys? (Tony)
Re: Getting the return code of a program opened as a pi <ittyspam@yahoo.com>
Re: glob in perl <usenet@morrow.me.uk>
Re: glob in perl (Peter Scott)
Matching strings with index – getting extra match (G)
Re: Matching strings with index – getting extra m <ittyspam@yahoo.com>
Re: Named parameters in method calls ctcgag@hotmail.com
NTP module <jwillmore@remove.adelphia.net>
Re: Perl project update <rdover@ev1.net>
Re: Perl project update <kkeller-usenet@wombat.san-francisco.ca.us>
Re: script working like daemon <jwillmore@remove.adelphia.net>
SOAP::Lite access to request variables by name (Matt Wilks)
Re: When to "use strict" when teaching? <cwilbur@mithril.chromatico.net>
Re: Why is Perl losing ground? <kirk@strauser.com>
Re: Why is Perl losing ground? <usenet@morrow.me.uk>
Re: Why is Perl losing ground? <kirk@strauser.com>
Re: Why is Perl losing ground? <peter@semantico.com>
Re: Why is Perl losing ground? (Walter Roberson)
Why references?? <thomas.deschepper.ecol@sintjozefscollege.be>
Re: Why references?? (Walter Roberson)
Re: Why references?? <usenet@morrow.me.uk>
Re: Why references?? ctcgag@hotmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 09 Feb 2004 16:21:43 GMT
From: Kien Ha <kha@rogers.com>
Subject: Re: [WWW::Mechanize] how to 'click' on javascript:next(1)
Message-Id: <rsOVb.47196$3YE1.26348@news04.bloor.is.net.cable.rogers.com>
Grzegorz Goryszewski wrote:
> Hello,
>
> with WWW::Mechanize I want to simulate click on link defined via Javascript,
> my perl code looks like:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use WWW::Mechanize ;
> my $w = WWW::Mechanize->new;
>
> $w->get("http://somepage"); #sorry cant uncover that
> $w->success or die "Nie moge zaladowac strony :(!";
>
> my @flinks = $w->find_all_links( url_regex => qr/next/i )
> or die "nie znalazlem linka\n";
>
> my ( $url, $title ) = @{$flinks[0]};
> print $url , "\n";
> $w->get( $url );
> ^^^^^^^^^^^^^^^^^^^^
> I'm getting this error : Can't locate object method "host" via package
> "URI::_foreign"
>
> My code shows "JavaScript:next(1)" as a link. The point is I don't know how
> to follow it.
follow_link :-)
Use the follow_link method which is a high level wrapper. It will
eventually do the 'get' automatically, and return a HTTP::Response
object if success. All documented on it's manpage.
for my $link ( @flinks ) {
my ( $url, $title ) = @$link;
$w->follow_link( url => $url );
die "Can't follow ", $url, $w->response->status_line
unless $w->success;
# do something with the $w->content;
$w->back; # go back up
}
Kien
------------------------------
Date: Mon, 9 Feb 2004 16:49:15 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [WWW::Mechanize] how to 'click' on javascript:next(1)
Message-Id: <c08dmb$luv$1@wisteria.csv.warwick.ac.uk>
Kien Ha <kha@rogers.com> wrote:
> Grzegorz Goryszewski wrote:
> > with WWW::Mechanize I want to simulate click on link defined via Javascript,
> > my perl code looks like:
> >
> > my ( $url, $title ) = @{$flinks[0]};
> > print $url , "\n";
> > $w->get( $url );
> > ^^^^^^^^^^^^^^^^^^^^
> > I'm getting this error : Can't locate object method "host" via package
> > "URI::_foreign"
> >
> > My code shows "JavaScript:next(1)" as a link. The point is I don't know how
> > to follow it.
>
> follow_link :-)
>
> Use the follow_link method which is a high level wrapper. It will
> eventually do the 'get' automatically, and return a HTTP::Response
> object if success. All documented on it's manpage.
This won't help. The problem is that WWW::Mechanize (or, actually,
LWP) doesn't support JavaScript. What you need to do is either
1. write an implementation of JavaScript in Perl, and, based on that,
write URI::javascript ;) or
2. find out what the JavaScript function next(1) does on that page and
do that manually.
Death to web designers who use JavaScript when they don't need to!
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk
------------------------------
Date: Mon, 9 Feb 2004 18:30:58 +0100
From: "Grzegorz Goryszewski" <gregory@pharmag.pl>
Subject: Re: [WWW::Mechanize] how to 'click' on javascript:next(1)
Message-Id: <c08fo5$35t$1@nemesis.news.tpi.pl>
Użytkownik "Ben Morrow" <usenet@morrow.me.uk> napisał w wiadomości
news:c08dmb$luv$1@wisteria.csv.warwick.ac.uk...
> 2. find out what the JavaScript function next(1) does on that page and
> do that manually.
Ben, is there any chance that I can implement this in perl :
function next(str){
document.forms['frm1'].reset();
document.forms['frm1'].strona.value=str;
document.forms['frm1'].submit();
}
?
Sorry if its OT but I'm still looking for perl solution :).
Regards.
GG
------------------------------
Date: Mon, 9 Feb 2004 17:59:18 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [WWW::Mechanize] how to 'click' on javascript:next(1)
Message-Id: <c08hpm$oo2$1@wisteria.csv.warwick.ac.uk>
"Grzegorz Goryszewski" <gregory@pharmag.pl> wrote:
>
> Użytkownik "Ben Morrow" <usenet@morrow.me.uk> napisał w wiadomości
> news:c08dmb$luv$1@wisteria.csv.warwick.ac.uk...
> > 2. find out what the JavaScript function next(1) does on that page and
> > do that manually.
>
> Ben, is there any chance that I can implement this in perl :
>
> function next(str){
> document.forms['frm1'].reset();
> document.forms['frm1'].strona.value=str;
> document.forms['frm1'].submit();
> }
>
> ?
Should be easy with WWW::Mechanize, that's what it's for... let me
see...
$mech->submit_form(
form_name => 'frm1',
fields => { strona => 'str' },
);
should do the trick.
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else * ben@morrow.me.uk
------------------------------
Date: Mon, 9 Feb 2004 17:45:17 +0100
From: "chatiman" <chatiman@free.fr>
Subject: Re: CGI.pm & multipart
Message-Id: <4027b918$0$28262$636a15ce@news.free.fr>
Sorry that was my fault ... The program was reading some data from STDIN
"gnari" <gnari@simnet.is> a écrit dans le message de news:
c083gc$uk$1@news.simnet.is...
> "chatiman" <chatiman@free.fr> wrote in message
> news:402758f7$0$28746$626a14ce@news.free.fr...
> > CGI.pm stops at initialisation with the error:
> > Malformed multipart POST: data truncated
> >
> > What's wrong ?
>
> my guess is that, due to malformed multipart POST,
> data was truncated and CGI stopped.
>
> seriously, we may need more info here, like:
> what did you do?
> did you look at the HTML that generated the POST?
> did you make a minimal program that still makes this happen?
> does a normal POST do this?
> ...
>
>
> gnari
>
>
>
------------------------------
Date: 09 Feb 2004 17:18:16 GMT
From: ctcgag@hotmail.com
Subject: Re: CGI.pm & multipart
Message-Id: <20040209121816.347$1Y@newsreader.com>
"chatiman" <chatiman@free.fr> wrote:
> CGI.pm stops at initialisation with the error:
> Malformed multipart POST: data truncated
>
> I'm using CGI.pm V 3.01
>
> What's wrong ?
Well, the most likely problem is that you have a malformed multipart POST.
Another possibility is that you have a corrupt CGI.pm. A couple years ago,
I had a problem (also manifesting in multipart post problems) which I
tracked down to the CGI which shipped with the system being hosed (it
claimed to be version 3.something, even though at the time 2.7something was
the newest version available. Replacing it with one from CPAN fixed the
problem.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 9 Feb 2004 09:57:18 -0800
From: hawkmoon1972@hotmail.com (Tony)
Subject: Re: DBI::mysql column names as hash keys?
Message-Id: <c90e5468.0402090957.3dceefec@posting.google.com>
Thanks for pointing me in the right direction guys.
For the record, this is what I ended up with:
$sth1 = $dbh->prepare("SELECT * FROM human where name = ?");
my $rv = $sth1->execute("Bob");
if ($rv > 0) {
while ($hash_ref = $sth1->fetchrow_hashref) {
$vars{"human"} = {%$hash_ref}; # THIS WAS THE ELUSIVE PART!!!
my $tt = Template->new;
$tt->process('test.txt', \%vars, 'test.txt.out');
}
} else {
printf "no results\n";
};
------------------------------
Date: Mon, 9 Feb 2004 11:53:17 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Getting the return code of a program opened as a pipe
Message-Id: <20040209115037.T483@dishwasher.cs.rpi.edu>
On Mon, 9 Feb 2004, Noel Sant wrote:
> Hi! Can anyone help, please?
<snip>
> The following program snippet does whar I want, except for the return code.
> When I just used the perl system function, it was fine, of course, but
> something in the camel book (p. 342) made me think I might get it when
> closing the pipe. Perhaps that's only in Unix systems. All I get is "1",
> whereas WZZIP gives "0" if OK.
> =====================
> # my $rc = system($command);
> open ZIP_OUTPUT, "$command |"
> or die "Error openng WZZIP output pipe etc."\n";
> while (<ZIP_OUTPUT>) {
> chomp;
> s/\s+$//; # trim blanks right
> next if /\\$/;
> next if /\/$/;
> print MESSAGES $_ . "\n";
> }
> my $rc = close ZIP_OUTPUT;
> =====================
This is exactly what close is supposed to do. From perldoc -f close:
"If the file handle came from a piped open close will additionally return
false if one of the other system calls involved fails or if the program
exits with non-zero status. (If the only problem was that the program
exited non-zero $! will be set to 0.) Closing a pipe also waits for the
process executing on the pipe to complete, in case you want to look at the
output of the pipe afterwards, and implicitly puts the exit status value
of that command into $?."
So if the external program is successful, close returns a true value. If
not, it returns a false value. The program's exit status is stored in $?
regardless.
Paul Lalli
------------------------------
Date: Mon, 9 Feb 2004 17:00:37 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: glob in perl
Message-Id: <c08ebl$ml5$1@wisteria.csv.warwick.ac.uk>
Andreas Boehm <andreas@andiboehm.de> wrote:
> >> DB<1> @a=glob("/home/sunny/share/User/Joerg/rho- SAX tryp/*");
> >> DB<3> x @a
> >>0 '/home/sunny/share/User/Joerg/rho-'
> >>1 'SAX'
> >> DB<4>
> >>Is this correct?
> >
> > Yup
>
> why?
Because that's what glob does! RTFM.
If you want the reason behind glob's behaviour, it is because 1. glob
used to fork csh to do the globbing and that's what csh did and
2. people with sense don't use names with spaces in so it's useful to
be able to do <*.c *.h> and have it DWIM.
> >>And does there exist a solution that correctly globs folders containing
> >>spaces in their names?
>
> > Don't use folder(spit!)^W^W directories with spaces in their names. It
> > will cause you much pain.
>
> but unix allows spaces in names since the seventies of the last
> century.
Unix allows any character in a filename except "\0" and /. That
doesn't mean using them is a good idea. Having spaces in names is fine
as long as all your tools are prepared to deal with that fact, and a
lot of unix tools are not. (glob and system/exec with one arg are the
only places I can think of where Perl does an implicit split on
whitespace, so it's a good tool to use to replace those like shell
that do it everywhere.)
> > File::Glob::bsd_glob will treat each argument as a separate
> > pattern, rather than splitting on whitespace.
>
> but the argument is quoted...
Perl Is Not Shell. glob takes one argument, splits that on whitespace,
and treats each part as a separate glob pattern. RTFM.
File::Glob::bsd_glob takes several arguments, and doesn't split them.
Ben
--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk
------------------------------
Date: Mon, 09 Feb 2004 17:35:17 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: glob in perl
Message-Id: <pxPVb.454092$ts4.447442@pd7tw3no>
In article <c083uj$13o9jq$1@uni-berlin.de>,
Andreas Boehm <andreas@andiboehm.de> writes:
>Hello,
>
>I found the following behavior of perls built-in glob, but do not know
>if this is correct.
>in debug and in normal mode globbing does the folling thing:
>
> DB<1> @a=glob("/home/sunny/share/User/Joerg/rho- SAX tryp/*");
> DB<3> x @a
>0 '/home/sunny/share/User/Joerg/rho-'
>1 'SAX'
> DB<4>
>
>Is this correct?
Yes. (glob() since 5.6.0 uses File::Glob, which uses BSD glob, which does not
consider ENOENT to be an error.)
>And does there exist a solution that correctly globs folders containing
>spaces in their names?
A couple come to mind:
$dir = "/home/sunny/share/User/Joerg/rho- SAX tryp";
@a = glob("\Q$dir\E/*");
@a = glob("'/home/sunny/share/User/Joerg/rho- SAX tryp/*'");
If you think about it, you would not get away with leaving those spaces
unprotected on a command line operation, so why should Perl's glob
behave any differently from the shell's?
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http//www.perlmedic.com/
------------------------------
Date: 9 Feb 2004 08:25:07 -0800
From: bay_dar@yahoo.com (G)
Subject: Matching strings with index – getting extra matches.
Message-Id: <cad04083.0402090825.2eba95a5@posting.google.com>
I’m looping through a sales_file looking for matches. The file
has a number of entries such as the following:
sales item aaa | m423a
sales item bbb | m423
sales item ccc | m423b
sales item ddd | 423
These refer to sales_item and code respectively.
Here is the code segment:
open FILE, "<$sales_file";
while (<FILE>) {
($sales_item, $code) = split /\|/;
if (index($code, $entered_code) != -1) {
$list .= "<br>" if ($list);
$list .= $sales_item;
}
} # while
close FILE;
The problem is, if the $entered_code is 423 I get matches for all 4
when I would only want matches for the fourth sales item “sales
item ddd” line. Similarly, an $entered_code of m423 would match
the first 3. Any suggestions on how I can get the right matches,
keeping in mind that I would prefer to do it in code, and not alter
the sales_file.
Thanks,
C
------------------------------
Date: Mon, 9 Feb 2004 11:46:26 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Matching strings with index – getting extra matches.
Message-Id: <20040209114426.X483@dishwasher.cs.rpi.edu>
On Mon, 9 Feb 2004, G wrote:
> I’m looping through a sales_file looking for matches. The file
> has a number of entries such as the following:
>
> sales item aaa | m423a
> sales item bbb | m423
> sales item ccc | m423b
> sales item ddd | 423
>
> These refer to sales_item and code respectively.
>
> Here is the code segment:
>
> open FILE, "<$sales_file";
> while (<FILE>) {
> ($sales_item, $code) = split /\|/;
> if (index($code, $entered_code) != -1) {
> $list .= "<br>" if ($list);
> $list .= $sales_item;
> }
> } # while
> close FILE;
>
> The problem is, if the $entered_code is 423 I get matches for all 4
> when I would only want matches for the fourth sales item “sales
> item ddd” line. Similarly, an $entered_code of m423 would match
> the first 3. Any suggestions on how I can get the right matches,
> keeping in mind that I would prefer to do it in code, and not alter
> the sales_file.
Replace the index() line with
if ($code =~ /^\s*$entered_code\s*$/) {
This will search the $code line for 'beginning of string, possible white
space, the code, possible white space, end of string', rather than just
"the code anywhere within the string" as you're doing now.
Paul Lalli
------------------------------
Date: 09 Feb 2004 17:28:34 GMT
From: ctcgag@hotmail.com
Subject: Re: Named parameters in method calls
Message-Id: <20040209122834.865$XH@newsreader.com>
fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
> Is the named parameter style of calling methods the officially right way
> to do it these days? Or is there some debate? I'm talking about
>
> my $foo = new Foo(FISH => 'tuna', DRESSING => 'mayo');
>
> as opposed to Foo('tuna', 'mayo');
>
> In other words if you do it the old (positional) way, is that considered
> either hopelessly old-fashioned and/or bad coding practice?
As far as I can tell, the named parameter method is common only when there
are lots of optional parameters. If all or most parameters are mandatory,
positional seems to be the common method.
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Mon, 09 Feb 2004 12:44:11 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: NTP module
Message-Id: <pan.2004.02.09.17.44.09.238987@remove.adelphia.net>
I need to monitor a NTP (time) server. I searched CPAN and did not see a
NTP module.
So, is there one ... and I missed it?
Thanks
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
They spell it "da Vinci" and pronounce it "da Vinchy".
Foreigners always spell better than they pronounce. -- Mark
Twain
------------------------------
Date: Mon, 09 Feb 2004 16:28:19 -0000
From: "Pope Bob" <rdover@ev1.net>
Subject: Re: Perl project update
Message-Id: <102fd93tm5640e7@corp.supernews.com>
Tad McClellan <tadmc@augustmail.com> wrote:
>edgrsprj <edgrsprj@ix.netcom.com> wrote:
>[ snip 40 lines]
>
>You seem to have missed the point that Keith was making...
And this suprises you?
------------------------------
Date: Mon, 9 Feb 2004 08:37:40 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Perl project update
Message-Id: <k0d80c.ctg.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-02-09, Michele Dondi <bik.mido@tiscalinet.it> wrote:
>
> Do not think that I'm being rude to you, but I can't understand what
> is the question in your long post, if there is a question.
>
> If there's not a question, then I can't understand how your article
> should be of any interest to anyone here.
To be fair, if the post had actually contained any Perl content
whatsoever, it probably could have been of interest whether or not there
was a Perl question.
I just hope the OP's earthquake analysis techniques are much better than
his programming techniques. My life (see email domain!) could depend on
it, or something.
- --keith
- --
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAJ7dShVcNCxZ5ID8RAh/UAJ4yylEm4J2Pj4NUlnd3KrU2dMyFWACfdcfg
Q2Ion5fdqKLIMEwJSl9AGJ0=
=URVS
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 09 Feb 2004 11:56:36 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: script working like daemon
Message-Id: <pan.2004.02.09.16.56.35.23637@remove.adelphia.net>
On Mon, 09 Feb 2004 04:52:21 -0800, murph wrote:
> i should write a script which sends a mail whenever a new user is
> trying to login to the system(linux) as a root. As much as i know that
> script should work like daemon(i think that i can write it ) , but i
> don't know what exactly should the script do ?
> How can i understand when someone try to login to the computer ?
> Any ideas ?
You could look at SWATCH (which is written in Perl and recommended by
various security sources). http://swatch.sourceforge.net/
Another option is to put together a script to read from a FIFO, alter
your syslog.conf file to include sending messages to the FIFO, and then do
something when a specified line is encountered.
I'm sure there are other ways to do it.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
The longer I am out of office, the more infallible I appear to
myself. -- Henry Kissinger
------------------------------
Date: 9 Feb 2004 09:19:57 -0800
From: mats_stairway@hotmail.com (Matt Wilks)
Subject: SOAP::Lite access to request variables by name
Message-Id: <5aba5789.0402090919.4d131ea2@posting.google.com>
I am designing a SOAP server, and use a very simple perl script to
hand the request onto my Handler module:
---
#!/usr/bin/perl
use strict;
use SOAP::Transport::HTTP;
use Handler;
SOAP::Transport::HTTP::CGI
-> dispatch_to('Handler')
-> handle;
---
My problem is that I cannot figure out how to access the SOAP request
from a client within the Handler module (in the file Handler.pm). I
would like to refer to the data passed by the client by the name of
the tags that they have used. For example, if the following appeared
in the body:
<LAST_NAME>Smith</LAST_NAME>
I would like to refer to that by the tag name, 'LAST_NAME'. Right
now, I am accessing them as parameters to the function that the client
calls. However, this only works if the client arranges the data in
the correct order in their SOAP request. If I could somehow access
them directly by name through the SOAP::SOM or something, that would
be ideal. Is something of this nature possible?
------------------------------
Date: Mon, 09 Feb 2004 17:59:45 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: When to "use strict" when teaching?
Message-Id: <87smhkw3b6.fsf@mithril.chromatico.net>
On the whole I agree with you, but I wanted to raise a few quibbles:
>>>>> "MJD" == Mark Jason Dominus <mjd@plover.com> writes:
MJD> I don't think that it works
MJD> to try to put it in without including the reason why, and I
MJD> think it's disrespectful to the students to try to do that
MJD> anyway. They're adults, they're professionals, and we should
MJD> suppose they can be trusted to make the right professional
MJD> decisions when provided with the facts.
We should suppose this, and often we do; which means that we get
burned even worse when we're wrong. Perhaps this is more a comment on
the caliber of the programmers I've worked with than on any
pedagogical techniques, but when I was charged with writing Perl
coding standards at a prior place of employment, I made strictures and
warnings mandatory -- not because I think they ought to be mandatory
in all cases, but because I don't think the sort of judgment that
allows a programmer to correctly determine whether he's better off
without them is something that arises after a few training sessions.
(The principal benefit of having it in the coding guidelines was that,
in a hypothetical code review, "why aren't you using strictures?" was
likely to be one of the first questions asked. Practically speaking,
the only other person who wound up writing any Perl was immune to code
reviews, and thought he was above strictures and warnings anyway,
which meant I spent nearly as much time rewriting his code as he spent
writing it in the first place.)
MJD> There is no such thing as a good programming practice that
MJD> does not make life easier, or a bad programming practice that
MJD> does not make life harder. If something makes life easier,
MJD> it is good programming practice; if it makes life more
MJD> difficult, it is bad programming practice. How could it be
MJD> otherwise?
But there *are* good programming practices that can make things harder
in the short term, and bad programming practices that can make things
easier in the short term. (Usually there's a lot of luck involved in
the latter.) It takes experience and the wisdom that comes from
reflecting upon experience to learn to weigh long-term good versus
short-term good, especially in an environment with multiple deadlines
and multiple projects and multiple goals which are constantly
changing. This is why good programming practices are taught in
schools and specified in coding guidelines, rather than allowing each
programmer of indifferent talent to reinvent them from the ground up.
MJD> The first problem is that cargo-cult programming promulgates
MJD> ineffective or destructive programming practices by elevating
MJD> them to that status of 'good programming practice'. [...]
MJD> The second problem of cargo-cult programming is that the
MJD> labeling process discourages critical thought about the
MJD> meaning of the labels. People are encouraged to adhere to
MJD> certain practices because they are 'good', and to avoid
MJD> others because they are 'bad'. The goodness and badness have
MJD> become divorced from anything in reality; [...]
Again, this may have more to do with the caliber of the programmers
I've worked with, but critical thought seems largely absent whether
cargo-cult programming practices are mandated or not. I concur that
in a perfect world competent professional programmers would weigh the
benefits of strictures and use them when appropriate, but I've also
observed that in this imperfect world not only are many of the people
employed as programmers neither competent nor professional, they have
little interest in achieving either status.
And so, the question becomes - what do you do when you recognize that
rules do not substitute for good judgment, but all you have is
mediocre to bad judgment, which may become good judgment in time? I
think the approach that you advocate is the correct one -- explain
strictures when it's pedagogically appropriate (which may mean "I want
you to notice this line now, and for the time being include it in all
your programs; we're going to discuss in depth what it does in session
8, after we've talked about some other concepts that it relates to,
but for now what you need to know is that it will make some types of
errors much easier to catch"), and strongly recommend that they be
used in all programs until the programmers have good reason to turn
them off.
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: Mon, 09 Feb 2004 16:40:06 GMT
From: Kirk Strauser <kirk@strauser.com>
Subject: Re: Why is Perl losing ground?
Message-Id: <87ad3syzsn.fsf@strauser.com>
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-02-09T15:54:40Z, Dominic <roqetman@hotmail.com> writes:
> As a programmer who is addicted to Perl, I am curious as to why Perl is
> losing ground to another bunch of languages [...]
Is it? It may not be getting the same buzz, but I haven't seen it
declining.
> namely: Python
I have to admit that I really, really like Python, and I've started using it
in places where I would've previously used Perl. It's a very personal
decision, though; Python is usually a closer match to the way *I* model
systems than Perl, but that's clearly not true for everyone.
> PHP=20
Oh, Lord. I can't stand PHP. It seems like someone wanted "Perl Lite" for
web scripting, and when it caught on and people started demanding more
functionality, they just started randomly adding portions of almost-Perl
until it compiled without too many warnings. I can't think of one single
reason why anyone would use PHP over Perl, other than "my free web host made
it available", which is just a made decision made cyclic.=20
=2D --=20
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAJ7dI5sRg+Y0CpvERAkIRAJ9BTJVCHAovKx/PyxMtwO40EWvKOQCeOpbN
5TsZzStJjFWS7iLfAogRTTg=3D
=3Dh8BP
=2D----END PGP SIGNATURE-----
------------------------------
Date: Mon, 9 Feb 2004 17:07:32 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why is Perl losing ground?
Message-Id: <c08eok$ml5$2@wisteria.csv.warwick.ac.uk>
Kirk Strauser <kirk@strauser.com> wrote:
> > As a programmer who is addicted to Perl, I am curious as to why Perl is
> > losing ground to another bunch of languages [...]
>
> Is it? It may not be getting the same buzz, but I haven't seen it
> declining.
Well, given that Once Upon A Time Perl was the only thing between
shell and C, it's not surprising that it's giving a bit. I don't think
the Perl community has suffered in any material way from Python et
al., though: rather the opposite.
> > > PHP
>
> Oh, Lord. I can't stand PHP. It seems like someone wanted "Perl Lite" for
> web scripting, and when it caught on and people started demanding more
> functionality, they just started randomly adding portions of almost-Perl
> until it compiled without too many warnings. I can't think of one single
> reason why anyone would use PHP over Perl, other than "my free web host made
> it available", which is just a made decision made cyclic.
PHP is great for what it was designed for: a simple way to put a small
amount of scripting into a basically static HTML page. It's been
stretched *waay* beyond that now, though, and needs the same sort of
major rewrite/rethink that happened perl4->perl5. (FWIW I have heard
from friends who actually use the language :) that the PHP folks are
doing something along these lines now).
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Mon, 09 Feb 2004 17:30:09 GMT
From: Kirk Strauser <kirk@strauser.com>
Subject: Re: Why is Perl losing ground?
Message-Id: <87vfmgxiyo.fsf@strauser.com>
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-02-09T17:07:32Z, Ben Morrow <usenet@morrow.me.uk> writes:
> PHP is great for what it was designed for: a simple way to put a small
> amount of scripting into a basically static HTML page.
Having used both, though, I honestly don't see what's easier or simpler
about PHP's syntax. It comes with syntax for embedding logic inside
presentation, granted, but any number of Perl modules do the same thing.
What I *have* noticed is that it tends to have many partially overlapping
functions that seem to differ mainly by whether you want to print the output
automatically, return it for further processing, or both - and distinguished
=2D From each other largely by putting the arguments in a random order. It=
's
very typical to see:
foo_do(bar, baz, qux)
foo_execute(baz, qux)
foo_exec(qux, bar, baz)
foo_dothis(bar)
Yet, somehow, people seem to think PHP is easier. I just don't understand.
=2D --=20
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAJ8LN5sRg+Y0CpvERAuhCAJ9RUqUIFTGrmt678oed0wz2AGH3jACfYFk8
/CTBFmO147EFBomYIxgjtxU=3D
=3D7G4S
=2D----END PGP SIGNATURE-----
------------------------------
Date: Mon, 09 Feb 2004 17:37:37 +0000
From: Peter Hickman <peter@semantico.com>
Subject: Re: Why is Perl losing ground?
Message-Id: <4027c561$0$29823$afc38c87@news.easynet.co.uk>
Dominic wrote:
> As a programmer who is addicted to Perl, I am curious as to why Perl is
> losing ground to another bunch of languages,
Is it? Where did you get this idea from?
> Is Perl just not "trendy" anymore?
Thats correct, it is no longer trendy and hasn't been for years. Thats a
good thing by the way, Perl is now a standard tool in the programmer's
toolbox and not a passing fad. CASE anyone?
> Does it still scare programmers who haven't used it?
Again where did you get this idea, some facts would be nice.
An important point that you are missing is that a lot of programmers who
code in Perl are just that programmers who happen to code in Perl. They
also code in a variety of languages (I use Ruby, Python and Tcl/Tk - I
must get round to using Eiffel). A programming language is not a
religion, except for the stupid, and a good programmer will learn and
use other languages just for the hell of it.
Thus the ranks of the Python and Ruby programmers are being swelled by
Perl programmers. Very few programmers who use Perl are abstaining from
Perl altogether. Sure there are some /religious/ types that use Java and
swear off Perl as the spawn of satan but these people are nutters just
like the people who swear that Perl is the one and only language.
Imagine a carpenter who only used a mallet - not much of a carpenter?
Why then should a programmer use only one language?
------------------------------
Date: 9 Feb 2004 17:39:43 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Why is Perl losing ground?
Message-Id: <c08gkv$iou$1@canopus.cc.umanitoba.ca>
In article <23OVb.1$196.899@news.nyc.globix.net>,
Dominic <roqetman@hotmail.com> wrote:
:As a programmer who is addicted to Perl, I am curious as to why Perl is
:losing ground to another bunch of languages
:Does it still scare programmers who haven't used it?
It still scares programmers who *have* used it ;-)
--
Everyone has a "Good Cause" for which they are prepared to spam.
-- Roberson's Law of the Internet
------------------------------
Date: Mon, 09 Feb 2004 17:41:02 +0100
From: Thomas Deschepper <thomas.deschepper.ecol@sintjozefscollege.be>
Subject: Why references??
Message-Id: <c08d6u$89k$1@news.worldonline.be>
I've been reading Beginning Per & Programming Perl from O'Reilly for some time
now and I'm getting used to references and how to grow them..
But why would someone use a reference if they can use a normal variable? Yeah, I
know, with references you can grow complex data structures, but in simple
programs, why would you use them (=references)?
Thanks for your (smart) answers :)
Greets from Belgium,
Thomas
------------------------------
Date: 9 Feb 2004 16:55:15 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Why references??
Message-Id: <c08e1j$hkm$1@canopus.cc.umanitoba.ca>
In article <c08d6u$89k$1@news.worldonline.be>,
Thomas Deschepper <thomas.deschepper.ecol@sintjozefscollege.be> wrote:
:I've been reading Beginning Per & Programming Perl from O'Reilly for some time
:now and I'm getting used to references and how to grow them..
:But why would someone use a reference if they can use a normal variable? Yeah, I
:know, with references you can grow complex data structures, but in simple
:programs, why would you use them (=references)?
I've used languages where every subroutine argument was call- by-
reference, and I've used languages where every subroutine argument
was call- by- value, and I've used languages where every subroutine
argument had to be explicitly declared as by-reference or by-value.
perl, though, implicitly passes a reference if possible, and
otherwise passes by value. In my opinion, that leads to too much
chance of making a mistake (and hence to unpredicted behaviour),
so I prefer to not count on call-by-reference behaviour and instead
explicitly pass through a reference if I'm expecting to change the
argument.
--
I've been working on a kernel
All the livelong night.
I've been working on a kernel
And it still won't work quite right. -- J. Benson & J. Doll
------------------------------
Date: Mon, 9 Feb 2004 17:10:40 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why references??
Message-Id: <c08eug$ml5$3@wisteria.csv.warwick.ac.uk>
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
> perl, though, implicitly passes a reference if possible, and
> otherwise passes by value.
Eh what? Perl always passes aliases into @_, and the standard idiom
of
my ($a, $b) = @_;
then makes copies. What's implicit about that?
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: 09 Feb 2004 18:53:08 GMT
From: ctcgag@hotmail.com
Subject: Re: Why references??
Message-Id: <20040209135308.774$aF@newsreader.com>
Thomas Deschepper <thomas.deschepper.ecol@sintjozefscollege.be> wrote:
> I've been reading Beginning Per & Programming Perl from O'Reilly for some
> time now and I'm getting used to references and how to grow them..
>
> But why would someone use a reference if they can use a normal variable?
I wouldn't use a reference if I could just as well use a normal variable,
unless I anticipate the program will eventually evolve such that I
couldn't use a normal variable there anymore. In that case I would
preemptively use a reference.
> Yeah, I know, with references you can grow complex data structures, but
> in simple programs, why would you use them (=references)?
I wouldn't. I'm not sure I understand your question. Do you often see
people gratuitiously using references?
use strict;
my $x;
my $y;
$$$$y=0;
while ($$$$x=<>) {
$$$$y+=$$$$x;
};
print $$$$y;
> Thanks for your (smart) answers :)
^
ass
Cheers,
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6100
***************************************