[11822] in Perl-Users-Digest
Perl-Users Digest, Issue: 5422 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 19 20:07:23 1999
Date: Mon, 19 Apr 99 17:00:19 -0700
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, 19 Apr 1999 Volume: 8 Number: 5422
Today's topics:
'die' function problem <alex@digi-q.com>
Re: 'die' function problem <tripix@tdi-net.freeserve.co.uk>
Re: [Perl For Win32] ActiveX control Question <cassell@mail.cor.epa.gov>
accepting input with space seemas@my-dejanews.com
Re: Another bug in Perl? (Andrew Haveland-Robinson)
Re: attach a subroutine to a filehandle (Corey Saltiel)
Help! CGI::Cookie script works fine, but problem when u <khowe@performance-net.com>
Re: Interpolating Variables for 'use' (Andrew Allen)
Re: Interpolating Variables for 'use' (M.J.T. Guy)
Re: Interpolating Variables for 'use' <tchrist@mox.perl.com>
Re: Making a hash of 2-D and 3-D Associative Arrays <uri@home.sysarch.com>
Re: newbie help need on environment variables (Tad McClellan)
Re: Parody script from Camel 1? (Tramm Hudson)
Re: Perl and the Windows API <tye@metronet.com>
Re: Perl Error Message??? (Larry Rosler)
purging old mail <debbie.simek@trw.com>
Re: Scripting language with LFN support? <cassell@mail.cor.epa.gov>
Re: Tool Reuse Considered Beneficial (was: New FAQ: How (Larry Rosler)
Re: Top 10 newbie errors? (Tad McClellan)
Re: Top 10 newbie errors? <jeromeo@atrieva.com>
Re: Top 10 newbie errors? (Kvan)
Re: Top 10 newbie errors? <ebohlman@netcom.com>
Re: Top 10 newbie errors? (Andrew Allen)
Re: Top 10 newbie errors? (Randal L. Schwartz)
Re: Top 10 newbie errors? (Larry Rosler)
Re: Using a Regexp <wyzelli@yahoo.com>
Wanna post, need programmer help <jean_barry@my-dejanews.com>
Re: Wanna post, need programmer help <cassell@mail.cor.epa.gov>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 19 Apr 1999 15:50:23 -0700
From: Alex Guberman <alex@digi-q.com>
Subject: 'die' function problem
Message-Id: <371BB32F.72FF@digi-q.com>
Hi,
By some reason 'die' function is not working for my script. I'm using
it for the open() error mesasge. It works if I say print though. I ran
it on WinNT and UNIX. Could somebody tell me what's my problem. The
script is attached bellow:
Best regards,
Alex Guberman
---------------------
RussianLink.com
Phone: (888) 553-4447
Fax: (603) 908-1083
-----------------script---------------------
#!/usr/bin/perl
$| = 1;
package main;
print "Content-type: text/html\n\n";
print "This is a test<BR>";
open ( TPL, "db.txt" ) || die "Problem, $!<BR>\n";
undef $/;
$tpl = <TPL>;
print "$tpl";
close TPL;
print "Die didn't work again";
------------------------------------------------
------------------------------
Date: Mon, 19 Apr 1999 23:47:05 +0100
From: "Wayne Keenan" <tripix@tdi-net.freeserve.co.uk>
Subject: Re: 'die' function problem
Message-Id: <7fgcaj$dec$1@news4.svr.pol.co.uk>
Alex Guberman wrote in message <371BB32F.72FF@digi-q.com>...
>By some reason 'die' function is not working for my script.
oh, but it is, your server logs know all about this.
#!/usr/bin/perl -w
>$| = 1;
package main; #huh? point?
use strict; #haaah
use CGI;
use CGI::Carp;
>
>print "Content-type: text/html\n\n";
>print "This is a test<BR>";
open ( TPL, "db.txt" ) || carp "Problem, $!<BR>\n";
>undef $/;
>$tpl = <TPL>;
>print "$tpl";
>close TPL;
print "Die didn't work again"; # I dont think you see this.
Or something like that, but then, a better answer is probably better found
in a CGI newsgroup.
Regards
Wayne
------------------------------
Date: Mon, 19 Apr 1999 16:05:01 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: [Perl For Win32] ActiveX control Question
Message-Id: <371BB69D.45DC599C@mail.cor.epa.gov>
Scott W wrote:
>
> Hi!
>
> Does Perl for Win32 currently support calling functions in ActiveX
> controls? If anyone knows if this is possible or how to do it then
> any help would be much appreciated. Thanks!
I'm not exactly sure what you're asking for. But if you read the
ActivePerl FAQ, you'll find info on PerlScript, which is an ActiveX
Scripting version of Perl. You should have installed it with your
installation of ActiveState Perl. If not, re-install.
If you're asking whether Perl supports the underlying features of
ActiveX, then I think the answer is also yes. But I can't point
you to an instant read-up-on-it location. But you might start with
the Win32::OLE documentation.
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: Mon, 19 Apr 1999 23:14:37 GMT
From: seemas@my-dejanews.com
Subject: accepting input with space
Message-Id: <7fgdcm$85u$1@nnrp1.dejanews.com>
Hi:
I'm a newbie to perl/cgi programming. How can I accept a firstname+lastname
set with a space in the middle and pass it on as one quoted value.
e.g Username: John Smith --> needed as "John Smith" in my application.
Thanks,
Seema
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 19 Apr 1999 22:57:15 GMT
From: andy@-nospam-haveland.com (Andrew Haveland-Robinson)
Subject: Re: Another bug in Perl?
Message-Id: <3734b317.361057812@news.demon.co.uk>
On 19 Apr 1999 14:19:53 -0600, Daniel Grisinger
<dgris@moiraine.dimensional.com> wrote:
>andy@-nospam-haveland.com (Andrew Haveland-Robinson) writes:
>
>> You would think this works OK...
>
>> $msgdec =~ s/(.)/uc sprintf("%02x",ord($1))/eg;
>
>> Well, 99.61% of the time it does... until $msgdec contains an LF
>> The LFs in the string are returned untouched.
>
>. does not match newlines unless you add the /s modifier to your
>regular expression.
Thanks - you've cleared it up beautifully... as it was part of a password,
I must've had a temporary blindness by considering it as just another
character instead of a newline.
However, it still doesn't explain why my fix worked by successfully
translating the newline without the s option!
Cheers,
Andy.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HRA Web Services Tel. +44 (0)1252-845697
6 Haywarden Place, Hartley Wintney, ICQ: 1331640
Hants RG27 8UA England Web: http://www.1HR.net
------------------------------
Date: Mon, 19 Apr 1999 23:04:46 GMT
From: corey@americanrecruitment.com (Corey Saltiel)
Subject: Re: attach a subroutine to a filehandle
Message-Id: <slrn7hnddh.ff.corey@valis.americanrecruitment.com>
On 19 Apr 1999 00:31:07 GMT, Broc Seib <bseib@jade.cc.purdue.edu> wrote:
>Corey Saltiel <corey@americanrecruitment.com> wrote:
>
>> Is it possible to open a filehandle as a pipe ( or alias/reference ...
>> thingy ) to a subroutine within the same script?
>
>> Am I even making any sense? (c;
>
>You might look at 'perldoc perltie' which talks about how to write
>code to implement a "tied" perl variable. Specifically, look at TIEHANDLE
>in the docs. This lets you do "something" when activity takes place
>on a filehandle.
>
OK - after trying your suggestion ( thanks, by the way! ), and
after a days worth of attempting a variety of possible solutions,
I am, once again, quite stumped.
All I want is to create a pipe which I print a command to, then
be able to read the resulting output of that pipe, line-by-line.
Here's code:
#!/usr/local/bin/perl
package EventEmails;
$| = 1;
sub TIEHANDLE { my $i; bless \$i, shift }
sub READLINE {
print SQLPLUS <<"EOF";
select stuff from table;
EOF
#exit; <<--- !
};
tie(*QUERY,'EventEmails');
open(SQLPLUS, '|sqlplus') or
die "Could not open pipe to sql*plus: $!\n";
while (<QUERY>) {
print "\$_ is $_"; <<--- ?!
}
All I want ( as can hopefully be seen ) is to simply
grab the output of the sql query and parse it. (!!)
I get the output that I expect ( a bunch of email addresses
and some other junk I intend to discard before printing
out ), but it all gets thrown out at once as soon I hit the
while loop, but "$_" only ever contains '1', and
only gets printed in HUGE spurts intermittently, and ONLY if
I uncomment the 'exit' -- but then the code just loops on
forever - first chunking out the sql results, and then
chunking out a huge clump of "$_ is 1"'s ... Ack!
This *couldn't* be too difficult a task, what am I not
understanding here?
Please help,
Thanks so much --
Corey
------------------------------
Date: Mon, 19 Apr 1999 18:49:21 -0300
From: "Kevin Howe" <khowe@performance-net.com>
Subject: Help! CGI::Cookie script works fine, but problem when using SSI's
Message-Id: <SvNS2.24008$134.255389@tor-nn1.netcom.ca>
Hi, I have an extremely simple script which reads a cookie and then prints
it.
The script works fine when called from the script path ex:
http://...cgi-bin/test.cgi
But it won't print when called from an SSI!
ex: <!--#INCLUDE virtual="/cgi-bin/test.cgi"-->
I am at a total loss here, it must have something to do with CGI::Cookie,
but I can't say for sure.
Can anyone shed some light?
Thanks,
Kevin
THE SCRIPT (test.cgi)
--------------------------------------------------------
use CGI::Cookie;
### Use this to set the cookie ##############
#%shopcart = (
# this => "that",
# color=> "red"
#);
#$cookie1 = new
CGI::Cookie(-name=>'shopcart',-value=>\%shopcart,-expires=>'+1h');
#print "Set-Cookie: $cookie1\n";
####################################
# fetch existing cookies
%cookies = fetch CGI::Cookie;
%shopcart = $cookies{'shopcart'}->value if ($cookies{'shopcart'});
print "Content-type: text/html\n\n";
print %shopcart;
------------------------------
Date: 19 Apr 1999 21:32:01 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Interpolating Variables for 'use'
Message-Id: <7fg7ch$juu$1@fcnews.fc.hp.com>
Kubla Khan (kubla_khan@rocketmail.com) wrote:
: I am trying to 'use' modules dynamically. I have the module name in a
: variable and would like to interpolate the variable as a string for the
: 'use' call.
: Does anyone know how to do this?
: ex.
: $module = "CGI";
: use $module;
: But the string is not interpolated correctly like that or with "$module"
: or {$module}...
Because it hasn't executed the assignment. 'use' is a compile-time
statement.
This works:
BEGIN {$module="CGI"; eval "use $module";}
but there's a nagging voice in my head saying "you don't _really_ want
to do that, do you?"
Andrew
------------------------------
Date: 19 Apr 1999 23:00:48 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Interpolating Variables for 'use'
Message-Id: <7fgcj0$d4f$1@pegasus.csx.cam.ac.uk>
In article <7fg7ch$juu$1@fcnews.fc.hp.com>, Andrew Allen <ada@fc.hp.com> wrote:
>This works:
>
>BEGIN {$module="CGI"; eval "use $module";}
>
>but there's a nagging voice in my head saying "you don't _really_ want
>to do that, do you?"
It's good there are voices in your head. You should always have
nagging voices whenever you use eval STRING. There's almost always
a better way to do it. In this particular case, learn to replace the
'use' by it's equivalent 'BEGIN { require ... }'. So:
BEGIN {$module="CGI"; require $module; $module->import }
Rats! That doesn't work. You have to write
BEGIN {$module="CGI"; require "$module.pm"; $module->import }
Exercise for the reader: why did the first try say
Unrecognized character \002 at ...
Mike Guy
------------------------------
Date: 19 Apr 1999 17:27:22 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Interpolating Variables for 'use'
Message-Id: <371bbbda@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:
:Rats! That doesn't work. You have to write
: BEGIN {$module="CGI"; require "$module.pm"; $module->import }
That won't work either. Try $module = "CGI::Carp".
--tom
--
"Perl5, surprisingly, makes it very easy to do OO programming. I suspect
that it does this much better than Larry ever intended."
--Dean Roehrich in <1994Oct5.140720.1511@driftwood.cray.com>
------------------------------
Date: 19 Apr 1999 17:52:11 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Making a hash of 2-D and 3-D Associative Arrays
Message-Id: <x7aew4l1mc.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> In article <x3y676sh5w7.fsf@tigre.matrox.com> on Mon, 19 Apr 1999
LR> 13:33:30 -0400, Ala Qumsieh <aqumsieh@matrox.com> says...
>> You can do anything in Perl. You just need to know how.
LR> Can I leap tall buildings in a single bound? Even a Turing
LR> machine can't do that. Wowee!!!
larry,
you are just an irrepressible kid!
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Mon, 19 Apr 1999 11:42:56 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie help need on environment variables
Message-Id: <0uiff7.tt2.ln@magna.metronet.com>
Lee Bennett (lee@old-chapel.demon.co.uk) wrote:
: How do I source environment variables from an OS file.
Perl FAQ, part 8:
"I {changed directory, modified my environment} in a perl script.
How come the change disappeared when I exited the script?
How do I get my changes to be visible?"
: What is the perl equivalent?
Parse the file yourself and make assignments to %ENV,
as Larry suggested.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 19 Apr 1999 15:00:00 -0600
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Parody script from Camel 1?
Message-Id: <7fg5gg$n5j@llama.swcp.com>
Keywords: markov perl tpop travesty
[posted and cc'd to TomC and original author]
In article <371b73c7@cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> wrote:
> aduncan@cs.ucsb.edu writes:
> :Alas! I've recycled (reasonable) my 1st edition Camel book, and lost
> :(unforgiveable) the script it contained to make parodies of text by
> :measuring word combination frequencies. Searched the Web and DejaNews
> :with no success. Can somebody post it? Thanks.
>
> You want /usr/src/perl5.005_56/eg/travesty for that. But see also the
> new K&P markov chainer:
^
|
+--- I belive the proper operator is K&&P. The bitwise operation
is not well defined on seminal authors and is not guarenteed
to produce the results that you expect (besides the clean
up afterwards is quite messy!).
In case you want more than two levels of chaining, check out my
modifications that support arbitrary depth:
http://www.dejanews.com/[ST_rn=qs]/getdoc.xp?AN=452735210&fmt=raw
The changes were very short, perhaps three major ones and several
minor ones to make the code 'strict compliant' and -w free.
There are a few fixes that could be done afterwards -- subsitute
($SEP) x $MAX_PREFIX
in place of the
map { $SEP } (1..$MAX_PREFIX)
construction.
I haven't heard anything from K||P regarding it; I believe that I
cc'd the original post to both of them.
Share and enjoy!
Tramm
--
o hudson@swcp.com tbhudso@cs.sandia.gov O___|
/|\ http://www.swcp.com/~hudson/ H 505.266.59.96 /\ \_
<< KC5RNF @ N5YYF.NM.AMPR.ORG W 505.284.24.32 \ \/\_\
0 U \_ |
------------------------------
Date: 19 Apr 1999 16:03:22 -0500
From: Tye McQueen <tye@metronet.com>
Subject: Re: Perl and the Windows API
Message-Id: <7fg5mq$gak@fumnix.metronet.com>
[comp.lang.perl.misc trimmed from follow-ups. In general, *.misc should
never be posted to if you are already posting to a more specific group.]
Eric Bohlman <ebohlman@netcom.com> writes:
) Scott W <swolfington@home.com> wrote:
) : Hi! I was wondering if there is a way to call Windows API functions
) : from within Perl? Is this possible? Thanks in advance!
)
) Yep, using the Win32::API module.
You can also do it using an XS extension. Many of these already
exist. The ones under Win32API:: are particularly faithful to the
API. If you are interested in APIs that you can't find a module
for yet, then rather than spending your time importing the API
using Win32::API, you might want to spend that time writing a
Win32API:: module so that others could benefit from your work.
I think I've got this down to where doing a Win32API:: extension
is about as much work as figuring out how to use the functions
with Win32::API but with better results. [Win32::API is a great
tool -- it just isn't the best choice when lots of code using lots
of APIs is involved.]
You'd need a C compiler and a good understanding of data types and
memory allocation issues. Using Win32::API avoids the need for
the C compiler but, for APIs with any argument types other than
simple integers or read-only strings, it requires a deeper
understanding of data types and memory allocation issues.
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
------------------------------
Date: Mon, 19 Apr 1999 14:02:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Error Message???
Message-Id: <MPG.118539db570973899898e1@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <371B8624.4C350057@inficad.com> on Mon, 19 Apr 1999 19:38:13
GMT, Ray A. Lopez <rdsys@inficad.com> says...
> The script (sorts a list of numbers) works fine, but I get an error
> message in my output which I don't seem to understand (or understand how
> to fix appropriately). Any idea on what I am doing wrong?
1. You are using a bubble sort [O(n ** 2)], instead of the Perl sort()
function, which uses quicksort [O(n log n)]. I hope this is just a
training exercise (or a homework problem -- same difference).
2. You are accessing the element past the end of the array.
...
> #!/usr/local/bin/perl -w
> use diagnostics;
> use strict;
Lots of gold stars!
> my @numbers = (2, 38, 28, 0, 34, 7, 14, 1);
> my $count = @numbers;
> my $num;
>
> print "@numbers\n";
> while ( $count > 0 ) {
> for ($num = 0; $num < $count; $num++ ) {
> if ( $numbers[$num] > $numbers[$num+1] ) {
Consider $num == $count - 1. The element $num[$count] doesn't exist.
> @numbers = swapnums($num, @numbers);
> }
> }
>
> $count--;
> }
> print "\n@numbers\n";
>
> sub swapnums {
> my ($ndx, @list) = @_;
> my $temp;
>
> $temp = $list[$ndx];
> $list[$ndx] = $list[$ndx+1];
> $list[$ndx+1] = $temp;
@list[$ndx, $ndx + 1] = @list[$ndx + 1, $ndx];
Isn't Perl wonderful? Now you don't need this function. But you don't
need the whole program either. :-)
> return @list;
> }
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 19 Apr 1999 08:33:04 -0700
From: Debbie Simek <debbie.simek@trw.com>
Subject: purging old mail
Message-Id: <371B4CAF.AC1BFB49@trw.com>
I'm trying to get back into programming after many years. I've been
creating some HTML web pages and now I'm trying to learn Perl. I've
been tasked to purge mail messages on our server that are older than 1
year. Since many people tend to keep messages too long, I'm sure this
is such a common procedure. Is this procedure in a library somewhere?
Debbie
------------------------------
Date: Mon, 19 Apr 1999 16:10:20 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Scripting language with LFN support?
Message-Id: <371BB7DC.2EF60053@mail.cor.epa.gov>
Sylvan Butler wrote:
>
> [snip]
>
> I'd probably pick perl as well, but my brother keeps raving about
> python. Both of those are available on Win32 and Unix platforms.
> Perl is probably a bit more widespread default...
Both Perl and Python are good choices, IMHO. But your preference
will depend on your prior experiences in computing, your CS coursework,
and your natural tendencies as a programmer and as a person.
You may want to try both, and decide which fits better with your
own personal style. I prefer Perl [well duh], but some people
love the consistent interface of Python [and hence hate Perl].
Of course, some people love Java too, so there's no accounting for
taste. :-)
> sdb
> --
> | Sylvan Butler | Not speaking for Hewlett-Packard | sbutler-boi.hp.com |
> | Watch out for my e-mail address. Thank UCE. #### change ^ to @ #### |
> They that can give up essential liberty to obtain a little temporary
> safety deserve neither liberty nor safety. --Benjamin Franklin, 1759
> "Don't Tread On Me!"
Hey, isn't that the Python motto? :-)
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: Mon, 19 Apr 1999 14:25:53 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Tool Reuse Considered Beneficial (was: New FAQ: How can I read in an entire file all at once?)
Message-Id: <MPG.11853f40497fdeef9898e2@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <m3u2ucbb33.fsf@moiraine.dimensional.com> on 19 Apr 1999
14:37:52 -0600, Daniel Grisinger <dgris@moiraine.dimensional.com>
says...
> Tom Christiansen <tchrist@mox.perl.com> writes:
...
> > Use the commands from the toolkit. That's what it's there for.
>
> Unix is a twisty maze of standards, all different.
The POSIX standard for commands such as cat(1) fixes this problem, for
all platforms that comply. Certainly all reasonably modern Unixes, plus
the MKS ToolKit for DOS/Windows. I can't speak for any others, for lack
of hands-on knowledge.
> If you want reliable code that can be moved from environment to
> environment then you _shouldn't_ use the toolkit.
>
> Period. Ever.
>
> You have no way of knowing exactly how the executable file
> `cat' will act on any arbitrary system. For all you know, the
> user has a veterinary diagnostic program for felines under
> that name. Hope it does what you expect.
See above. It is expected to do what I expect. :-)
> Besides, I don't have time to chase bugs in 15 million different
> implementations of cat(1) when
>
> while(<>) { do_stuff($_) }>
>
> works more reliably.
I agree about not using 'cat', because the Perl equivalent is fairly
trivial and fairly fast. But consider 'sort' on a very large set of
large files as one example of something I wouldn't care to reinvent.
Others have found 'grep' and some other C-implemented commands to be
faster than their Perl equivalent code.
> > Do *not* reinvent the wheel.
>
> I find this rather amusing coming from the man who is busy
> reinventing _all_ of the wheels in the unix toolbox.
He is not reinventing them. He is reimplementing them in Perl, and they
will conform to the standard, so be very portable.
> > F u cn rd ths u cnt spl wrth a dm!
>
> My spelling is certainly worth at least a dime. :-)
>
> dgris
Off-topic for this thread, but relevant to reinventing the wheel: How
is the Perl Function Repository? Does it need to be reconstituted?
Does it need a new host?
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 19 Apr 1999 11:56:07 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Top 10 newbie errors?
Message-Id: <nmjff7.tt2.ln@magna.metronet.com>
John Callender (jbc@shell2.la.best.com) wrote:
: I'm putting together a list of the top 10 ways that people new to both
: Perl and programming screw things up. (Screw things up in their
: scripts, I mean. Thus, "Posting CGI questions to c.l.p.m." or "Asking
: for advice without posting the suspect code" would not qualify.)
: Here, in rough order of decreasing frequency (by which I really mean,
: in the rough order in which they occurred to me), is what I think I've
: done most often myself. I'm curious whether other folks' lists are
: similar.
I would eliminate all of the ones that generate syntax
errors (or warnings).
Syntax errors are easy to find (a stupid 'ol machine can
find those).
Logic, and other, errors that silently result in incorrect
output when using both -w and "use strict" would seem more
worth the time to collect.
: 1. Block-delimiting curly brackets (braces) not matching up properly.
: 2. Failing to supply the closing quotation character on a quoted
: string.
: 3. Parentheses in a compound conditional test (e.g., if '(((this) and
: (that)) or (that))' ) not matching up properly.
Just syntax errors.
Fixed in 20 seconds, not worth remembering.
: 4. Variable-name "creep" (i.e., using $walnuts in one place and $walnut
: in another, while intending for them to refer to the same variable).
This never happens to Experienced Perl Programmers, since they
always use -w and "use strict". (well, it happens, but it gets
fixed in 20 seconds)
There must be some reason that they do that...
... New Perl Programmers should emulate them :-)
: 5. Using '$' instead of '%' in front of the hash variable's name in an
: argument to the 'keys' function.
Syntax error.
: 6. Confusing assignment with numeric equality in a logical test ('='
: vs. '==').
: 7. Confusing string and numeric equality in a logical test ('==' vs.
: 'eq').
Those only generate messages sometimes.
So they are good to list.
: 8. Transferring a script from Windows to Unix in binary-mode FTP,
: resulting in a corrupt shebang line (among others).
There is nothing specific to Perl in that one.
: 9. Omitting a statement-ending semicolon.
Syntax error.
: 10. Improperly terminating a here-document quotation (e.g., by having a
: bogus space after the terminating string).
Syntax error.
: It's interesting to me how my favorite goofs has evolved in the 4 years
: or so I've been learning Perl. For example, I rarely screw up the
: string-vs.-numeric equality thing these days, but I still can count on
: one or two curly-bracket goofs in any decent-sized script (yes, I know
: I should be using a real editor that checks that for me).
So (IMO, of course), all but 6 and 7 are easily corrected if
you are using both -w and "use strict".
So, that would make the #1 and #2 mistakes not using the -w
switch and not using the "use strict" pragma
:-)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 19 Apr 1999 14:19:42 -0700
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: Top 10 newbie errors?
Message-Id: <371B9DEE.16AE65A7@atrieva.com>
Clinton Pierce wrote:
> >1. Not using warnings and strict( #/bin/perl -w and use strict;).
>
> I (respectfully) disagree on adding "use strict" pragma to a list of
> things that newbies fail do to that "screw[s] things up".
Well you're no fun... ;->
I think strict should be used by newbies because it forces them to
understand scoping and variable life, both of which are important for
moving beyond newbie-land. As a side effect, it also encourages good
blocking and style. It's a good habit, and it's best to start those
early.
> For true newbies "use strict" only seems to get in the way of quickly
> writing short, effective scripts that Do Something Useful. "use strict"
> makes a B&D Language out of an easy-to-hack glue language. Once someone
> is using modules, lots of functions, structures, and other more complex
> language structures...THEN I think it's time for "use strict".
I disagree. In fact, learning strict pragma is much easier on those
short, concise scripts than it is on large complex structures, where
previous bad habits come back to bite you.
> By then, they're not exactly perl/programming newbies.
That's right. By then, they are really confused because perl doesn't do
"what they thought they told it to do." I argue that one should use
strict until they are familiar enough with the language to consciously
*NOT* use it, and understand why.
> Turning on "use strict" (especially vars & subs) pretty much makes
> speaking Perl baby-talk impossible. It's like a 2-year old speaking
> baby-talk being constantly interrupted by an English PhD. correcting his
> grammar and pronunciation.
Odd thing about baby-talk is it quickly becomes the norm if you let it.
At some point, one needs to speak with adults, and the earlier one
learns the vernacular, the better.
There is very little difference between:
my($foo) = q{bar};
and
$foo = q{bar};
Easily understood by infants and doktors alike!
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Mon, 19 Apr 1999 21:07:22 GMT
From: kvan@dis.dk (Kvan)
Subject: Re: Top 10 newbie errors?
Message-Id: <371b9989.54227605@news.newsguy.com>
On Mon, 19 Apr 1999 19:17:06 GMT, cpierce1@ford.com (Clinton Pierce)
wrote:
>For true newbies "use strict" only seems to get in the way of quickly
>writing short, effective scripts that Do Something Useful. "use strict"
>makes a B&D Language out of an easy-to-hack glue language. Once someone
>is using modules, lots of functions, structures, and other more complex
>language structures...THEN I think it's time for "use strict".
Amen! "use strict" isn't a good thing in all situations, especially,
as you mention, short, effective scripts of the kind a newbie (often)
wants to write.
That said, "use strict" should be one of the first thing you turn to
if your script DOESN'T work. I personally don't feel comfortable
developing with "use strict", but will use to find hard-to-detect
errors.
Bottom line is, there are some of us who are definitely not
comfortable with the B&D of "use strict", and it shouldn't necessarily
be a default for newbies. It should definitely be in their
bug-tracking kit, though.
Kvan, avoiding B&D languages whenever possible.
-------Casper Kvan Clausen------ | 'A *person* is smart. People are
---------<kvan@dis.dk>---------- | dumb, panicky, dangerous animals
| and you know it.'
| - "K" in Men in Black.
------------------------------
Date: Mon, 19 Apr 1999 22:00:57 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Top 10 newbie errors?
Message-Id: <ebohlmanFAGIHL.sK@netcom.com>
John Callender <jbc@shell2.la.best.com> wrote:
: I'm putting together a list of the top 10 ways that people new to both
: Perl and programming screw things up. (Screw things up in their
: scripts, I mean. Thus, "Posting CGI questions to c.l.p.m." or "Asking
: for advice without posting the suspect code" would not qualify.)
A useful companion list might be one of the most common error-prone
constructs people use. IOW, code that may "work" but is non-robust or is
likely to break during maintenance. It's impossible to completely avoid
visits from Mr. Murphy, but some people write code that amounts to buying
him a set of round-trip first-class tickets and booking him in the
penthouse suite of the nearest luxury hotel. Some off the top of my head:
1) Using the symbol table in place of a programmer-defined hash (i.e.
using symbolic references without a *very* good reason).
2) Severe Leaning Toothpick Syndrome resulting from lack of knowledge
about (or willingness to use) alternative quote and regex delimiters.
3) Using multiple substr()'s to break apart fixed-length records. This
requires specifying two numbers per field, one which usually has to be
hand-calculated.
4) Using hand-rolled (or cut-and-pasted) CGI parameter decoding code.
------------------------------
Date: 19 Apr 1999 22:51:34 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Top 10 newbie errors?
Message-Id: <7fgc1m$lpf$1@fcnews.fc.hp.com>
Eric Bohlman (ebohlman@netcom.com) wrote:
: A useful companion list might be one of the most common error-prone
: constructs people use. IOW, code that may "work" but is non-robust or is
: likely to break during maintenance. It's impossible to completely avoid
: visits from Mr. Murphy, but some people write code that amounts to buying
: him a set of round-trip first-class tickets and booking him in the
: penthouse suite of the nearest luxury hotel. Some off the top of my head:
: 1) Using the symbol table in place of a programmer-defined hash (i.e.
: using symbolic references without a *very* good reason).
I'd add to this:
Passing "parameters" around in globals or perl built-in vars (except
@_ ;)
Fear (or ignorance) of "map" and "grep" leading to the proliferation
of integer-indexed for-loops to process lists (which aren't hard to
write, but are easy to write badly ;)
Andrew
------------------------------
Date: 19 Apr 1999 16:18:39 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Top 10 newbie errors?
Message-Id: <m1yajoi4hc.fsf@halfdome.holdit.com>
>>>>> "Eric" == Eric Bohlman <ebohlman@netcom.com> writes:
Eric> 3) Using multiple substr()'s to break apart fixed-length records. This
Eric> requires specifying two numbers per field, one which usually has to be
Eric> hand-calculated.
Or my favorite, along this line, using the "save delimiter" memory
mode of split, when a good m//g would have done it much better.
Admittedly, many of these are from old dead camel carcass code, but it
keeps getting propogated with viral intensity. More entries for the
cargo cult programming registry.
print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Mon, 19 Apr 1999 16:35:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Top 10 newbie errors?
Message-Id: <MPG.11855dac77cf01eb9898e3@nntp.hpl.hp.com>
In article <ebohlmanFAGIHL.sK@netcom.com> on Mon, 19 Apr 1999 22:00:57
GMT, Eric Bohlman <ebohlman@netcom.com> says...
...
> A useful companion list might be one of the most common error-prone
> constructs people use. IOW, code that may "work" but is non-robust or is
> likely to break during maintenance. It's impossible to completely avoid
> visits from Mr. Murphy, but some people write code that amounts to buying
> him a set of round-trip first-class tickets and booking him in the
> penthouse suite of the nearest luxury hotel. Some off the top of my head:
...
> 3) Using multiple substr()'s to break apart fixed-length records. This
> requires specifying two numbers per field, one which usually has to be
> hand-calculated.
Not really. The following is adapted from a benchmark I posted today.
But it is not the best way to do the split, nevertheless. A regex or
unpack() are faster and much easier to write. So maybe it belongs on
your list anyway.
my @lengths = (7, (4) x 8);
my $i = 0;
my @fields = map substr($string, ($i += $_) - $_, $_), @lengths;
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 20 Apr 1999 09:02:12 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Using a Regexp
Message-Id: <12PS2.50$my2.3321@vic.nntp.telstra.net>
You are right... lots of really good answers.
There was a problem with my news server.
Also when I re-posted I thought this might have been a better title to the
question...
Thanks for the help ppl
Wyzelli
David Cassell wrote in message <371B71EC.B8629306@mail.cor.epa.gov>...
>Wyzelli wrote:
>> [big snip of entire post]
>
>Umm, pardon me, but isn't this the identical post you submitted
>yesterday?
>
>And didn't you get some excellent answers to that thread?
>
>I don't understand why you're re-submitting this. Is there a problem
>with your news server?
>
>David
>--
>David Cassell, OAO
>cassell@mail.cor.epa.gov
>Senior Computing Specialist phone: (541)
>754-4468
>mathematical statistician fax: (541)
>754-4716
------------------------------
Date: Mon, 19 Apr 1999 22:00:49 GMT
From: jeanb <jean_barry@my-dejanews.com>
Subject: Wanna post, need programmer help
Message-Id: <7fg92b$4eo$1@nnrp1.dejanews.com>
I've been trying to get trough to this forum a couples of times and no luck.
Can someone tell me what's going on.
--
Jean Barry
Jean_barry@my-dejanews.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 19 Apr 1999 16:54:57 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Wanna post, need programmer help
Message-Id: <371BC251.E22532CB@mail.cor.epa.gov>
jeanb wrote:
>
> I've been trying to get trough to this forum a couples of times and no luck.
> Can someone tell me what's going on.
You got through this time. Perhaps there's a problem with your server.
Now then, what's your Perl question?
David, who used to watch you all the time in "Burke's Law"...
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5422
**************************************