[25439] in Perl-Users-Digest
Perl-Users Digest, Issue: 7684 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 23 14:05:37 2005
Date: Sun, 23 Jan 2005 11:05:16 -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 Sun, 23 Jan 2005 Volume: 10 Number: 7684
Today's topics:
Re: [perl-python] 20050121 file reading & writing (Anno Siegel)
ANNOUNCE: DBIx::HTML::LinkedMenus V 1.07 <ron@savage.net.au>
counting perl src when have nested requires? (Ted Johnson)
Re: counting perl src when have nested requires? <spamtrap@dot-app.org>
Re: counting perl src when have nested requires? (Anno Siegel)
Re: FAQ 3.19 How can I free an array or hash so my prog <mjcarman@mchsi.com>
Re: FAQ 3.19 How can I free an array or hash so my prog <d@adelphia.net>
Re: FAQ 3.19 How can I free an array or hash so my prog <dha@panix.com>
Re: find <joe@inwap.com>
Re: how to write a tutorial <xah@xahlee.org>
Re: how to write a tutorial <cbfalconer@yahoo.com>
Re: how to write a tutorial <danperl@rogers.com>
multiple modifiers: a possible solution ioneabu@yahoo.com
Re: multiple modifiers: a possible solution (Anno Siegel)
Re: newbie perl questions (Anno Siegel)
Re: Send mail question <tadmc@augustmail.com>
Re: Send mail question <amead@comcast.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Jan 2005 18:27:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [perl-python] 20050121 file reading & writing
Message-Id: <ct0qbb$o30$2@mamenchi.zrz.TU-Berlin.DE>
Gian Mario Tagliaretti <g.tagliarettiNO@SPAMparafernalia.org> wrote in comp.lang.perl.misc:
> Xah Lee wrote:
>
> > # the second argument of open can be
> > # 'w' for write (overwrite exsiting file)
> > # 'a' for append (ditto)
In Python, appending to a file overwrites it? Interesting...
> > # 'r' or read only
>
> are you sure you didn't forget something?
>
> > # reading the one line
> > # line = f.realine()
>
> wrong
>
> > [...]
>
> Maybe you didn't get the fact the you won't see a flame starting between
> python people and perl friends?
The Perl part, thankfully snipped, is so wrong that it hurts. This stuff
is so sloppy, it isn't even good for flame bait.
Anno
------------------------------
Date: Sun, 23 Jan 2005 04:20:16 GMT
From: Ron Savage <ron@savage.net.au>
Subject: ANNOUNCE: DBIx::HTML::LinkedMenus V 1.07
Message-Id: <IAs31z.1u2u@zorch.sf-bay.org>
The pure Perl module DBIx::HTML::LinkedMenus V 1.07
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.
On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.
An extract from the docs:
1.07 Tue Jan 18 22:14:00 2005
- Add new parameters to new(): base_prompt, base_value, linked_prompt and linked_value
which allow you to specify strings, and their corresponding values, to be output
at the top of the 2 menus. The default behaviour is identical to the previous version.
See examples/test-linked-menus.cgi. Original patch by Sean McKenna
- Update docs
- Update examples/test-linked-menus.cgi
- Note: Originally I omitted such options because I thought these values should always come
from the database, but this change just gives you another way to do it. In fact, this
way is neater since you can supply strings which you would not normally have in the
database in the first place
--
Cheers
Ron Savage, ron@savage.net.au on 23/01/2005
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company
------------------------------
Date: Sun, 23 Jan 2005 04:41:22 GMT
From: ted@estaff05.mayfield.hp.com (Ted Johnson)
Subject: counting perl src when have nested requires?
Message-Id: <csv8p7$lm5@estaff05.mayfield.hp.com>
I've inherited a perl program and libs which have extremely
nested series of "require" statements.
For example, in the main file, "foo.pl" we have:
#!/usr/bin/perl
require "lib1.pl";
require "lib2.pl";
require "lib3.pl";
...
# main() routine starts here...
But each of the libs in turn "require" other libs, eg,
"lib1.pl" has:
require "sublib11.pl";
require "sublib22.pl";
require "sublib33.pl";
...
And each sublib in turn "require"s yet more sublibs, eg,
"sublib11.pl" has:
require "sublib111.pl";
require "sublib429.pl";
require "sublib937.pl";
Is there any way to --->count the lines of perl src<---
by inserting some sort of magic statement right after
the "main()" line in the master file, "foo.pl"?
Thanks in advance!
-Ted
------------------------------
Date: Sat, 22 Jan 2005 23:39:19 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: counting perl src when have nested requires?
Message-Id: <JI2dnSofHPTkt27cRVn-tQ@adelphia.com>
Ted Johnson wrote:
> I've inherited a perl program and libs which have extremely
> nested series of "require" statements.
...
> Is there any way to --->count the lines of perl src<---
> by inserting some sort of magic statement right after
> the "main()" line in the master file, "foo.pl"?
You can get a list of all the files that have been included with use(),
require(), or do() from the special hash %INC. The keys are the values as
given in your script(s), and the values are the actual paths at which the
files were found.
So, in the simplest case, it could be as simple as this:
system("wc -l " . join(' ', values(%INC)));
Like I said, that's the simple case - obviously, if there are spaces or
other funky stuff in the paths to these files, you'll need to deal with
that by escaping them properly before executing the "wc -l" shell command.
I'll leave that as an exercise for the reader. :-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 23 Jan 2005 17:46:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: counting perl src when have nested requires?
Message-Id: <ct0ntp$o30$1@mamenchi.zrz.TU-Berlin.DE>
Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> Ted Johnson wrote:
>
> > I've inherited a perl program and libs which have extremely
> > nested series of "require" statements.
> ...
> > Is there any way to --->count the lines of perl src<---
> > by inserting some sort of magic statement right after
> > the "main()" line in the master file, "foo.pl"?
What "main()" line? Perl isn't C.
> You can get a list of all the files that have been included with use(),
> require(), or do() from the special hash %INC. The keys are the values as
> given in your script(s), and the values are the actual paths at which the
> files were found.
>
> So, in the simplest case, it could be as simple as this:
>
> system("wc -l " . join(' ', values(%INC)));
A solid approach, but it will report all modules loaded anywhere in the
program (up to the point where %INC is evaluated). The OP seems to be
interested in the modules loaded directly or indirectly by one specific
"use" statement.
To make it selective that way (and to add a little magic) I propose
this:
END {
my @report_these; # collect modules to report
sub report_loading {
push @report_these, $_[ 1];
return; # undef, so search continues
}
# Line counting left as an exercise
print "$_ => $INC{ $_}\n" for @report_these;
}
use Some::Stuff;
use lib \ &report_loading;
use Nested::Module;
no lib \ &report_loading;
use Other::Stuff;
The END block will only report what has been loaded between the "use lib ..."
and "no lib ..." statements. More pairs could be added.
This makes use of the fact that you can put a code object on @INC that will
be called when a module is loaded. The feature is described with "require".
Anno
------------------------------
Date: 22 Jan 2005 15:34:13 -0800
From: "Michael Carman" <mjcarman@mchsi.com>
Subject: Re: FAQ 3.19 How can I free an array or hash so my program shrinks?
Message-Id: <1106436853.488792.112130@f14g2000cwb.googlegroups.com>
There's at least one error in this answer and there is enough overlap
between this and "How can I make my Perl program take less memory?"
that the answers to them should be coordinated and probably reference
each other. Here is my proposal for revised text:
You usually can't. Memory allocated to lexicals (i.e. my() variables)
cannot be reclaimed or reused even if they go out of scope. It is
reserved in case the variables come back into scope. Memory allocated
to global variables can be reused (within your program) by using
undef()ing and/or delete().
On most operating systems, memory allocated to a program can never be
returned to the system. That's why long-running programs sometimes re-
exec themselves. Some operating systems (notably, systems that use
mmap(2) for allocating large chunks of memory) can reclaim memory that
is no longer used, but on such systems, perl must be configured and
compiled to use the OS's malloc, not perl's.
In general, memory allocation and de-allocation isn't something you can
or should be worrying about much in Perl.
See also "How can I make my Perl program take less memory?"
-mjc
------------------------------
Date: Sat, 22 Jan 2005 23:53:52 -0800
From: DJO <d@adelphia.net>
Subject: Re: FAQ 3.19 How can I free an array or hash so my program shrinks?
Message-Id: <neGdnfSTgJKCxW7cRVn-gA@adelphia.com>
Michael Carman wrote:
> There's at least one error in this answer and there is enough overlap
> between this and "How can I make my Perl program take less memory?"
> that the answers to them should be coordinated and probably reference
> each other. Here is my proposal for revised text:
The text in question is from perlfaq3.pod; part of the core Perl
distribution. Patches may be submitted to the Perl5Porters for review
and possible adoption as outlined in perlbug.pod. Posting patches here
in comp.lang.perl.misc is not how it's handled.
------------------------------
Date: Sun, 23 Jan 2005 18:46:29 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: FAQ 3.19 How can I free an array or hash so my program shrinks?
Message-Id: <slrncv7s85.s21.dha@panix2.panix.com>
On 2005-01-23, brian d foy <comdog@panix.com> wrote:
> In article <neGdnfSTgJKCxW7cRVn-gA@adelphia.com>, DJO <d@adelphia.net>
> wrote:
>
>> The text in question is from perlfaq3.pod; part of the core Perl
>> distribution. Patches may be submitted to the Perl5Porters for review
>> and possible adoption as outlined in perlbug.pod. Posting patches here
>> in comp.lang.perl.misc is not how it's handled.
>
> Actually, I am handling it exactly like that. One of the benefits of the
> autoposts is the scrutiny of the people who read this forum. I check
> the replies and put any corrections into my queue.
>
> Other than a response to one of these autoposts, the correct place to
> post a correction or addition is perlfaq-workers@perl.org, not p5p.
A cursory glance at where I'd assume this info would be (perldoc -q
(patch|submit), perlbug) doesn't provide it. Maybe this should be a faq.
:-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"I didn't say I'd never slay another vampire. It's not like I have
fluffy bunny feelings about them. I'm just not going to get too
extra-curricular about it." - Buffy
------------------------------
Date: Sun, 23 Jan 2005 03:58:05 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: find
Message-Id: <AMudnfCyRLfNDG7cRVn-rw@comcast.com>
Mihau wrote:
> Hi,
>
> How to convert this Perl line to work on Windows system:
> open(FILES, "find . -type f |");
C:\>find2perl . -type f -print >prog1.pl
C:\>perl prog1.pl
C:\>more prog1.pl
C:\>perldoc File::Find
-Joe
------------------------------
Date: 23 Jan 2005 01:28:28 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: Re: how to write a tutorial
Message-Id: <1106472508.591411.40140@c13g2000cwb.googlegroups.com>
adding to my previosu comment...
In the Python tutorial:
http://python.org/doc/2.3.4/tut/node11.html
the beginning two paragraphs should be deleted. Nobody gives a shit
except a few smug academicians where the author wrote it for pleasing
himself. For 99% of readers, it is incomprehensible and irrelevant.
the first paragraph of 9.1 "A Word About Terminology" is epitome of
masturbation. The entire 9.1 is not necessary.
Large part of 9.2 "Python Scopes and Name Spaces" is again
masturbatory.
--
Most texts in computing are written by authors to defend and showcase
their existence against their peers. In a tutorial, nobody cares how
the language compared to x y and z, or what technicality is it all
about, or some humorous snippet of history only funny to the author
himself.
Particularly for texts in a tutorial context, you want to write it as
simple as possible covering the most useful basic functionalities and
concepts, and self-contained. Not showcasing your knowledge of history
of languages or your linguistic lineage byways.
For example this chapter 9 on Objects, it is not difficult to write it
without making a show of lingoes. One simply write what is of Python,
without thinking about relation to xyz languages or the "computer
science" establishment and their ways of thinkings of namespaces and
scopes and dynamic and statics and inheritances ... fucking bags of
shit.
Also, in the computing industry, documentations and tutorials often
lacks examples. Especially important in tutorials. Be fewer in words,
more in examples. (for example, unix man pages are full of arcane
abstract syntax specifications and inner-working technicalities while
most don't contain a single example of usage that is much needed.)
also, this does not mean beginning to write for dummies as the highly
successful series of "xyz for Dummies" books. These are successful
because the corpus of textbook writers are all inclined and habituated
to chalk up to jargons and intellectualization on the accounts of their
own esteem and careers. Dummy books are moronic because they assumed
the general readers are morons.
PS Another illustrative case is the official Java Tutorial. Python
tutorial is to the point on the whole. The Java Tutorial is completely
asinine. Chalking up to rocket sciences every chance with unhelpful and
misleading drivel.
Xah
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
------------------------------
Date: Sun, 23 Jan 2005 10:47:10 GMT
From: CBFalconer <cbfalconer@yahoo.com>
Subject: Re: how to write a tutorial
Message-Id: <41F37E6D.296D9EB1@yahoo.com>
Xah Lee wrote:
>
... snip ...
>
> the first paragraph of 9.1 "A Word About Terminology" is epitome
> of masturbation. The entire 9.1 is not necessary.
>
> Large part of 9.2 "Python Scopes and Name Spaces" is again
> masturbatory.
PLONK for excessive OT crossposting and trolling.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
------------------------------
Date: Sun, 23 Jan 2005 10:24:20 -0500
From: "Dan Perl" <danperl@rogers.com>
Subject: Re: how to write a tutorial
Message-Id: <BZudndPVSuwxXG7cRVn-og@rogers.com>
"Xah Lee" <xah@xahlee.org> wrote in message
news:1106472508.591411.40140@c13g2000cwb.googlegroups.com...
> the beginning two paragraphs should be deleted. Nobody gives a shit
> except a few smug academicians where the author wrote it for pleasing
> himself. For 99% of readers, it is incomprehensible and irrelevant.
>
> the first paragraph of 9.1 "A Word About Terminology" is epitome of
> masturbation. The entire 9.1 is not necessary.
>
> Large part of 9.2 "Python Scopes and Name Spaces" is again
> masturbatory.
This is a perfect description for your own postings. Why don't you follow
your own advice?
------------------------------
Date: 23 Jan 2005 01:52:23 -0800
From: ioneabu@yahoo.com
Subject: multiple modifiers: a possible solution
Message-Id: <1106461168.507351.270230@f14g2000cwb.googlegroups.com>
Sorry if the formatting gets messed up. I am not on my own computer
now and Google is the only way I can post this from here. Try this
out:
#!/usr/bin/perl
use warnings;
use strict;
my @a = ('a','b','c');
my @b = ('1','2','3','4','5');
my $c = 1;
my $d = multimod('print for @a for @b if $c');
eval $d;
print "\n$d\n";
sub multimod
{
my $mods = "if|for|while|unless";
my $a = shift;
my ($b,$c,$d);
while ($a =~ /^(.*?)($mods)(.*?)($mods)(.*)/)
{
$c = $d = '';
if ($4 and $5)
{
$a = "$4$5";
$c = $4;
$d = $5;
}
if ($1) {$b = "$2($3) {$1}"}
else {$b = "$2($3) {$b}"}
}
return "$c($d) {$b}" if $c and $d;
}
------------------------------
Date: 23 Jan 2005 15:55:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: multiple modifiers: a possible solution
Message-Id: <ct0he7$kk9$1@mamenchi.zrz.TU-Berlin.DE>
<ioneabu@yahoo.com> wrote in comp.lang.perl.misc:
> Sorry if the formatting gets messed up.
Predictably it did.
> I am not on my own computer
> now and Google is the only way I can post this from here. Try this
> out:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> my @a = ('a','b','c');
> my @b = ('1','2','3','4','5');
> my $c = 1;
> my $d = multimod('print for @a for @b if $c');
> eval $d;
> print "\n$d\n";
Yes, that may work, but it's beside the point. The point of combining
statement modifiers is elegance, (or at least tightness) of code. Calling
a sub and eval'ing the result doesn't give us that.
Your example shows that it can be done in Perl, but there never was much
doubt about that.
[code snipped]
Anno
------------------------------
Date: 23 Jan 2005 18:46:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: newbie perl questions
Message-Id: <ct0rdp$o30$3@mamenchi.zrz.TU-Berlin.DE>
Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
>
> A full list of Perl builtin functions can be found in the perlfunc
> manual. If you are learning Perl it's really worth speding 5-10
> minuites skimming this document.
The section "Perl Functions by Category" in that document is particularly
noteworthy, not to memorize it, but to remember it's there. Not only
beginners often face the question "I'm sure Perl can do this, but how
could it be called?". The answer can usually be found right there.
Anno
------------------------------
Date: Sat, 22 Jan 2005 17:27:01 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Send mail question
Message-Id: <slrncv5oa5.6tr.tadmc@magna.augustmail.com>
Antony <nospam@cdtoday.co.uk> wrote:
> I found this perl script on a website regarding sending emails.
It is worth *less* than what you paid for it.
> my $reply_to = "Reply-to: foo@bar.org";
There is a bug there that warnings would have found.
> my $to = my@email.co.uk;
There is a bug there too.
> runmeail {
Looks like another bug, where is the "sub" keyword?
Is "runemail" misspelled there?
Is this the actual code or did you re-type it?
> print $query->header;
> print "Confirmation of your submission will be emailed to you.";
It says that it will output HTML but then it does not output HTML.
> However when I go and run the script from the browser, I don't recieve any
> emails.
1) Contact the author of the script for support
or
2) Learn Perl programming
or
3) Hire someone who already knows Perl programming to write
a useable version for you
> Is this because the script must be posted too,
What does "posted" mean?
> processes an email automatically,
There is a Frequently Asked Question about mail:
perldoc -q mail
How do I send mail?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 23 Jan 2005 04:42:22 -0600
From: Alan Mead <amead@comcast.net>
Subject: Re: Send mail question
Message-Id: <pan.2005.01.23.10.42.20.914764@comcast.net>
Star date: Sat, 22 Jan 2005 23:01:51 +0000, Antony's log:
> I found this perl script on a website regarding sending emails.
>[snip]
> However when I go and run the script from the browser, I don't recieve any
> emails. Is this because the script must be posted too, or have I simply
> missed something out? My aim is to incorporate it into a larger script which
> processes an email automatically, however this part is obviously not
> working.
I don't know what "run the script from the browser" means. Tad points out
numerous problems. You definitely have to have the script installed on
the server, you need to ensure that the script can find sendmail using the
path in the script, etc.
You need to be clearer about what precisely is happening. Is email being
generated but then lost/misdirected/caught by spam? How do you know? Are
you running this on a Unix-ish or a Windows server? I've found that
sending email can be tricky for reasons that have nothing to do with Perl.
FWIW, my favorite package for doing this is MIME-Lite which makes it very
easy to send email directly or using SMTP. The MIME-Lite documentation is
concise and informative.
-Alan
------------------------------
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 7684
***************************************