[25466] in Perl-Users-Digest
Perl-Users Digest, Issue: 7711 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 30 03:05:29 2005
Date: Sun, 30 Jan 2005 00:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 30 Jan 2005 Volume: 10 Number: 7711
Today's topics:
[perl-python] sending email <xah@xahlee.org>
Re: [perl-python] sending email <danperl@rogers.com>
Re: cgi scripts stops executing? squash@peoriadesignweb.com
Re: FAQ 3.4 How do I find which modules are installed o <joe@inwap.com>
Re: FAQ 4.16 How can I find the Julian Day? <jkeen_via_google@yahoo.com>
Re: Help with hash reference to a module <wksmith@optonline.net>
Re: Message body <noreply@gunnar.cc>
Re: Message body <see_sig@invalid>
Re: Perl loops should use break, not last <abigail@abigail.nl>
Re: Perl loops should use break, not last <abigail@abigail.nl>
Re: Perl loops should use break, not last xhoster@gmail.com
Re: Perl loops should use break, not last <nodj.athensspam@surfeu.fi.useless>
Re: Regular Expression Question on /i <tadmc@augustmail.com>
Saving an image from external site asdfq213rr23we@yahoo.com
Re: Saving an image from external site <matternc@comcast.net>
Re: Saving an image from external site <nospam@bigpond.com>
Re: Saving an image from external site <see_sig@invalid>
Re: Saving an image from external site <tadmc@augustmail.com>
Re: Search Through List <tadmc@augustmail.com>
Re: Tom Christiansen's books review <postmaster@castleamber.com>
Re: what's OOP's jargons and complexities? <larry_wallet@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 29 Jan 2005 15:36:05 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: [perl-python] sending email
Message-Id: <1107041765.890014.112530@c13g2000cwb.googlegroups.com>
# -*- coding: utf-8 -*-
# Python
# Suppose you want to spam your friend, and you have lots of
# friends. The solution is to write a program to do it. After a gander
# at python docs, one easily found the module for the job.
# see http://python.org/doc/2.3.4/lib/SMTP-example.html
# the code is a bit long with the command line, but the key lies at
# the bottom four lines. The gist is this:
import smtplib
smtpServer='smtp.yourdomain.com';
fromAddr='xah@xahlee.org';
toAddr='xah@xahlee.org';
text='''Subject: newfound love
Hi friend,
long time no write, i have a new manifesto i
think it would be of interest for you to peruse.
...
'''
server = smtplib.SMTP(smtpServer)
server.set_debuglevel(1)
server.sendmail(fromAddr, toAddr, text)
server.quit()
# save this file as x.py and run it.
# it should send out the mail.
# the set_debuglevel() is nice because you see all the interactions
# with the smtp server. Useful when you want to see what's going on
# with a smtp server.
-------------------------
in Perl, there are not just one, two, or 3 modules that does the job,
each with slight problems. Here's how the situation stands as of 2001
March:
For Perl libraries that deals with RFC 821, I personally know of
three:
* Mail::Mailer. Mentioned in most Perl books.
Written or maintained by Graham Barr.
* Mail::Send, maintained by Graham Barr , originally
written by Tim Bunce.
* Mail::Sendmail by Milivoj Ivkovic.
The first two has glaring problems. I'm sorry i forgot what they
are. I think Mail::Mailer has a bug on the from field. i.e. it ignores
what you gave. I'm currently using Mail::Sendmail, and according to a
ex-colleague, it has problems with some DNS mail exchange entries.
for some discussion of the plethora of Perl mail modules and their
short-cummings, see http://alma.ch/perl/mail.htm
--------------------
Xah
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
------------------------------
Date: Sat, 29 Jan 2005 20:56:35 -0500
From: "Dan Perl" <danperl@rogers.com>
Subject: Re: [perl-python] sending email
Message-Id: <bLOdnW7H-bBEo2HcRVn-pg@rogers.com>
I recommend the example in the Python Library Reference as a better example:
http://www.python.org/doc/lib/SMTP-example.html. You can also find the
entire description of the smtplib module in the same section
(http://www.python.org/doc/lib/module-smtplib.html).
Xah Lee's example is missing:
- The login() call needed by SMTP hosts that require authentication.
- The 'From:' and 'To:' addresses in the header of the email. They
are not mandatory, but you would probably use them.
------------------------------
Date: 29 Jan 2005 22:31:17 -0800
From: squash@peoriadesignweb.com
Subject: Re: cgi scripts stops executing?
Message-Id: <1107066677.874845.180500@f14g2000cwb.googlegroups.com>
Thanks for all the replies. I just discovered there was a bug in my
code logic !! So the randomly stop executing was not the culprit.
------------------------------
Date: Sat, 29 Jan 2005 23:03:51 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <wpSdnW5F9vtGG2HcRVn-tg@comcast.com>
PerlFAQ Server wrote:
> 3.4: How do I find which modules are installed on my system?
I would add to the posted answer this perl one-liner:
perl -MCPAN -e autobundle
unix% more .cpan/Bundle/Snapshot*
C:\> more \.cpan\Bundle\Snapshot*
-Joe
------------------------------
Date: Sun, 30 Jan 2005 04:26:14 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: FAQ 4.16 How can I find the Julian Day?
Message-Id: <GlZKd.4538$VW3.3701@trndny07>
PerlFAQ Server wrote:
>
> 4.16: How can I find the Julian Day?
>
> [snip]
>
> There is too many details and much confusion on this issue to cover in
s/is/are/ for number agreement between verb and predicate nominative.
------------------------------
Date: Sat, 29 Jan 2005 18:24:27 -0500
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Help with hash reference to a module
Message-Id: <JWUKd.2661$_S6.1659@fe12.lga>
"Joe" <joeblow@joes.com> wrote in message
news:Xns95EDA4F29F714joeblowjoescom@216.221.81.119...
> Hello all,
>
> Old C programmer here. Trying to pass a reference to a hash to a sub
> routine in a module.
> Have seen many posts about references, nothing seems to work in the
case
> of modules.
The "Old C Programmer" probably thinks that perl prototypes mean the
same thing as "C" function prototypes. Although they appear similar,
the intent is quite different.
Refer to the prototype section of perldoc perlsub.
"...Because the intent of this feature is primarily to let you
define subroutines that work like built-in functions,..."
Unlike "C", they provide only a limit compile-time type checking. The
effect depends on the use (or non-use) of ampersand and parens in the
call. (I never can remember these rules. They are documented in detail
in the section referenced above.) I strongly recommend against routine
use of perl prototypes.
I do not see your error, but I suspect that your attempt to use
prototypes contributes to it.
Bill
------------------------------
Date: Sun, 30 Jan 2005 00:24:44 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Message body
Message-Id: <362kguF4rcc3qU1@individual.net>
[ Please do not top post! ]
Antony wrote:
> A. Sinan Unur wrote:
>> Antony wrote:
>>>I am trying to read an email into an array, using the POP method.
>>
>> CPAN is your friend. You can use Mail::POP3Client.
>
> Thanks for your reply. I was however hoping to use Net::POP3 module as the
> basis, because the script is already formatted for this.
That would work fine as well.
Post the code you have tried so far (or rather a short but runnable code
fragment that illustrates what you tried), and somebody may be able to
help you fix it.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Jan 2005 22:33:13 -0500
From: Bob Walton <see_sig@invalid>
Subject: Re: Message body
Message-Id: <41fc5607$1_1@127.0.0.1>
Antony wrote:
...
> I am trying to read an email into an array, using the POP method. However I
> can read each of the lines using if($line =~ m/Subject: /) { (as the subject
> for example), but how do I read the main email content/topic/body into an
> array, as it doesnt appear to have a header title.
Well, your question has nothing to do with Perl, but: The email
headers end with the first null line (or the first occurance of
"\n\n"). Everything after that is message body until either end
of file or the next line that matches /^From /.
If there is something picky wrong with what I said, well, that's
what you get for asking an email note format question in a Perl
newsgroup.
Others have rightly pointed out that modules are your friend, and
you need never know such detail if you use them. The further you
go, the more true this is -- I would guess that handling
attachments will be the next topic, for example.
...
> Antony
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: 30 Jan 2005 00:04:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl loops should use break, not last
Message-Id: <slrncvo947.a9.abigail@alexandra.abigail.nl>
Matija Papec (perl@my-header.org) wrote on MMMMCLXIX September MCMXCIII
in <URL:news:dmcnv0tclggthkelp49b0uf0fj50uiv6o8@4ax.com>:
;; X-Ftn-To: Jeremy Morton
;;
;; "Jeremy Morton" <ask@me.com> wrote:
;; >Probably been mentioned before but I fail to see why Perl changed the
;; >'break' keyword to 'last', in loops. Bear with me on this - it seems
;; >semantically more accurate to say 'break' - you're immediately breaking out
;; >of the loop. 'last' makes it sound like the current loop will be the last,
;; >but not that the execution should be stopped immediately, whereas break
;; >makes it sound like the latter.
;;
;; I'm guessing, "last" was picked because it's short and it sounds good along
;; with "next". Further, "break" could blur things for C people as his
;; "continue" friend is already used for something else.
One of the reasons why the three loop control constructs are named
'last', 'redo' and 'next' is that they are all the same length.
One of the reasons 'last' isn't called 'break' is that 'last' isn't
the same as 'break'. 'break' breaks the current loop - while 'last'
takes an optional argument, indicating the top level loop that will
be exited.
Abigail
--
perl -swleprint -- -_=Just\ another\ Perl\ Hacker
------------------------------
Date: 30 Jan 2005 00:06:59 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl loops should use break, not last
Message-Id: <slrncvo992.a9.abigail@alexandra.abigail.nl>
Jeremy Morton (ask@me.com) wrote on MMMMCLXIX September MCMXCIII in
<URL:news:41fbbbc0$0$26014$fa0fcedb@news.zen.co.uk>:
}} Matija Papec <perl@my-header.org> wrote:
}} > X-Ftn-To: Jeremy Morton
}} >
}} > "Jeremy Morton" <ask@me.com> wrote:
}} >> Probably been mentioned before but I fail to see why Perl changed the
}} >> 'break' keyword to 'last', in loops. Bear with me on this - it seems
}} >> semantically more accurate to say 'break' - you're immediately
}} >> breaking out of the loop. 'last' makes it sound like the current
}} >> loop will be the last, but not that the execution should be stopped
}} >> immediately, whereas break makes it sound like the latter.
}} >
}} > I'm guessing, "last" was picked because it's short and it sounds good
}} > along with "next".
}}
}} That's a good reason to choose a keyword, because it 'sounds good'?
Yes.
}} Heh.
}} It doesn't make semantic sense, and that's far more important IMHO.
What do you mean, it doesn't make semantic sense? The semantics of 'last'
are what they are defined to be.
}} > Further, "break" could blur things for C people as
}} > his "continue" friend is already used for something else.
}}
}} Yes, I don't quite understand why 'continue' is used the way it is,
}} either... that doesn't make much sense. However i'd still rather have
}} 'break' meaning what it does in most other languages i've come across. You
}} don't even have to do away with 'last'... just alias break to mean the same
}} thing.
Why? If you really want 'break' to be an alias for 'last', write a
source filter. It'll be a pretty trivial one.
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: 30 Jan 2005 03:19:50 GMT
From: xhoster@gmail.com
Subject: Re: Perl loops should use break, not last
Message-Id: <20050129221950.696$gY@newsreader.com>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
> "Jeremy Morton" <ask@me.com> wrote
>
> > Probably been mentioned before but I fail to see why Perl changed the
> > 'break' keyword to 'last', in loops. Bear with me on this - it seems
> > semantically more accurate to say 'break' -
>
> I have a sneaking suspicion that you are trolling, but I will indulge
> you anyway. You can think of 'last' as 'this is the last statement to be
> excuted in this loop'. At least, that is why it made sense to me the
> first time I started learning Perl.
>
> > 'last' makes it sound like the current loop will be the last,
>
> Your terminology is odd. How can the current loop be the last?
By not executing another time.
> How could
> a statement in one loop affect whether or not other loops are excuted?
By doing a bunch of machine level crap behind the scenes, just the same
way that everything in a high-level language does everything.
> Are you saying, if I have:
>
> my @animals = qw(cat dog dino);
>
> for my $animal (@animals) {
> last if $animal eq 'dog';
> }
>
> for my $animal (@animals) {
> print uc $animal, "\n";
> }
>
> The second loop will not be excuted due to the 'last' statement in the
> first loop.
No, I'm pretty sure that is not what he is saying.
More like
for my $animal (@animals) {
last if $animal eq 'dog';
print $animal;
};
Would print 'dog', but not anything in @animals after 'dog'.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Sun, 30 Jan 2005 10:05:46 +0200
From: "Jussi Mononen" <nodj.athensspam@surfeu.fi.useless>
Subject: Re: Perl loops should use break, not last
Message-Id: <cti4d8$5ql$1@nyytiset.pp.htv.fi>
> One thing from C that'd be really useful is to do away with the required
> braces in one-line if/then/else blocks, like this:
>
> if ($foo)
> func1($foo);
> elsif ($bar)
> func2($bar, $z);
> else
> return;
That is just prone to errors. What if you had to add some functionality into
one of the blocks? You would have to add the braces and forgetting to add
them is easy.
> I don't know if somebody already suggested this for Perl 6, but I think
> it'd be a nice improvement. That and a real switch statement. :-)
http://www.perl6.org/doc/design/apo/A04.html#rfc_022__control_flow__builtin_switch_statement
/jUSSi
------------------------------
Date: Sat, 29 Jan 2005 17:09:39 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regular Expression Question on /i
Message-Id: <slrncvo5tj.7uc.tadmc@magna.augustmail.com>
amyl@paxemail.com <amyl@paxemail.com> wrote:
> Thank you so much.
Thank _who_ so much?
It is customary to quote some context when composing a followp.
Have you seen the Posting Guidelines that are posted here frequently?
> I had no idea about "perldoc".
Have you seen the Posting Guidelines that are posted here frequently?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 Jan 2005 18:05:29 -0800
From: asdfq213rr23we@yahoo.com
Subject: Saving an image from external site
Message-Id: <1107050729.451951.74720@c13g2000cwb.googlegroups.com>
Hi
In Perl, how can I grab an image through its URL and save it on my
server?
Ex: save www.site.com/image.jpg onto a dir on my server (another.com)
Im looking at setting a cronjob that through this perl script grabs
this specific image once an hour and puts it on my server
Thanks
------------------------------
Date: Sat, 29 Jan 2005 21:19:12 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Saving an image from external site
Message-Id: <8JWdnSbL7-692WHcRVn-qQ@comcast.com>
asdfq213rr23we@yahoo.com wrote:
> Hi
>
> In Perl, how can I grab an image through its URL and save it on my
> server?
>
> Ex: save www.site.com/image.jpg onto a dir on my server (another.com)
>
> Im looking at setting a cronjob that through this perl script grabs
> this specific image once an hour and puts it on my server
>
> Thanks
You want LWP::Simple. In fact, you may want to dispense with Perl
altogether and use wget, but LWP::Simple is the way to go if you
want to use Perl.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Sun, 30 Jan 2005 13:18:36 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Saving an image from external site
Message-Id: <36320eF4s2jlpU2@individual.net>
Chris Mattern wrote:
> asdfq213rr23we@yahoo.com wrote:
>
>> Hi
>>
>> In Perl, how can I grab an image through its URL and save it on my
>> server?
>>
>> Ex: save www.site.com/image.jpg onto a dir on my server (another.com)
>>
>> Im looking at setting a cronjob that through this perl script grabs
>> this specific image once an hour and puts it on my server
>>
>> Thanks
>
> You want LWP::Simple. In fact, you may want to dispense with Perl
> altogether and use wget, but LWP::Simple is the way to go if you
> want to use Perl.
>
I use cron & wget:
13,28,43,58 * * * * wget http://XXX.com -O /home/aaa/XXX >/dev/null 2>&1
gtoomey
------------------------------
Date: Sat, 29 Jan 2005 22:19:28 -0500
From: Bob Walton <see_sig@invalid>
Subject: Re: Saving an image from external site
Message-Id: <41fc52cf_1@127.0.0.1>
asdfq213rr23we@yahoo.com wrote:
...
> In Perl, how can I grab an image through its URL and save it on my
> server?
>
> Ex: save www.site.com/image.jpg onto a dir on my server (another.com)
That's a one-liner:
perl -MLWP::Simple -e
"binmode(STDOUT);getprint('http://www.site.com/image.jpg')" >file.jpg
(the above is one line; it may have wrapped)
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Sat, 29 Jan 2005 21:31:04 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Saving an image from external site
Message-Id: <slrncvol7o.8h3.tadmc@magna.augustmail.com>
asdfq213rr23we@yahoo.com <asdfq213rr23we@yahoo.com> wrote:
> In Perl, how can I grab an image through its URL
The same way you grab HTML through its URL.
perldoc -q HTML
How do I fetch an HTML file?
> and save it on my
> server?
That depends on what kind of access you have to this "server".
> Im looking at setting a cronjob
On this "server" or somewhere else?
> that through this perl script grabs
> this specific image
> once an hour and puts it on my server
use LWP::Simple for downloading the image.
We can't help with how to put it on your server if we don'
know what access you have available to you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 29 Jan 2005 17:15:19 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Search Through List
Message-Id: <slrncvo687.7uc.tadmc@magna.augustmail.com>
Martin Kissner <news@chaos-net.de> wrote:
> Tad McClellan wrote :
>> Martin Kissner <news@chaos-net.de> wrote:
>>> Tad McClellan wrote :
>>>> Martin Kissner <news@chaos-net.de> wrote:
>>>>> if ($teammate =~ /\b$_\b/i ) # Case does not matter
>> The primary reason it is better IMO is because it *looks like*
>> an equality test.
>>
>> $teammate =~ /^$_$/i vs. lc $teammate eq lc $_
>>
>> You have to think about the first one for a second to realize
>> that it is an equality test in disguise.
> If one would look at it really strictly it should be
> $teammate eq $_
> since Jones ne JONES
No, that would be for looking at the # Case matters
statement really strictly.
We were discussing the # Case does not matter
errr, case. :-)
Looking at it strictly is also looking at it literally then.
(I *like it* when it looks like what it means.)
> To me this is mainly a question of understanding Perl.
I don't see it that way.
It is mainly a question of communicating in the most clear
way possible. It is Software Engineering rather than Perl.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 30 Jan 2005 02:08:55 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Tom Christiansen's books review
Message-Id: <Xns95EDCCF6AEDB0castleamber@130.133.1.4>
Xah Lee wrote:
> Tom Christiansen used to have a Perl books review here
> http://language.perl.com/critiques/
>
> does anyone know where to find it now?
> thanks.
http://www.perl.com/pub/a/language/critiques/index.html looks very empty to
me. It looks like someone messed up at perl.com...
http://www.google.com/search?q=%22Camel%20Critiques%22
Also, I understand it's quite old (Not updated since 1998).
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 29 Jan 2005 20:46:21 -0800
From: "Larry" <larry_wallet@yahoo.com>
Subject: Re: what's OOP's jargons and complexities?
Message-Id: <1107060381.623163.19850@z14g2000cwz.googlegroups.com>
Xah Lee wrote:
> in computer languages, often a function definition looks like this:
> xah@xahlee.org
> http://xahlee.org/PageTwo_dir/more.html
Your ideas are original, insightful and simply reflect incredibly deep
creative genius. I have read your work and I want to hire you for
highly classified work in software design and philosophical writing.
Would you possibly be available to meet with me in my secret mountain
compound to discuss terms?
Larry
------------------------------
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 7711
***************************************