[23073] in Perl-Users-Digest
Perl-Users Digest, Issue: 5294 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 30 18:10:38 2003
Date: Wed, 30 Jul 2003 15:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 30 Jul 2003 Volume: 10 Number: 5294
Today's topics:
Read from SSL IMAP <hasting@agere.com>
Re: Read from SSL IMAP <jwillmore@cyberia.com>
Re: Read from SSL IMAP <emschwar@ldl.fc.hp.com>
Re: remote readdir() <nobull@mail.com>
removing some text (Tony W)
Re: removing some text <trammell+usenet@hypersloth.invalid>
Re: removing some text <nobull@mail.com>
Re: removing some text (Tad McClellan)
Re: split alternative using regexp? (Greg)
Re: weird "perl -e" behaviour <krahnj@acm.org>
Re: Win32 Ole <mikeflan@earthlink.net>
Re: Win32 Ole <bart.lateur@pandora.be>
Re: Win32 Ole <mikeflan@earthlink.net>
Re: zero but true? <bart.lateur@pandora.be>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 30 Jul 2003 16:15:38 -0400
From: "Joe Hasting" <hasting@agere.com>
Subject: Read from SSL IMAP
Message-Id: <bg991a$81k$1@alageremail2.agere.com>
I seem to be going in circles in trying to get some sample code I have to
read from a SSL IMAP server. (the sample code is at the bottom). I have
downloaded the required modules from CPAN, Mail-IMAPClient-2.1.4.tar.gz,
IO-Socket-SSL-0.94.tar.gz, Mail-Audit-Attach-0.93.tar.gz, and
Mail-Audit-2.1.tar.gz. I then found that Mail::Internet is required, so I
got MailTools-1.15.tar.gz. I've gotten alittle further, but it now fails
in the Internet.pm saying that it cannt find 'use AutoLoader'.
I am stuck becuase I do not know where to find this, and a CPAN and internet
search were unsucessful. I guess that it is in an existing module (like
Mail::Internet was in MailTools), but I can't find it. Could someone who
has used these modules in the past give some guidance?
thanks
J
---sample code
--note, I am not an admin, so I've installed the modules in the root
home/hasting/scripts/HELP/PERL/mod/
--note, I also edited the server, user, and password when testing, I just
didn;t paste it here.
use strict;
use lib qw(/home/hasting/scripts/HELP/PERL/mod/Mail-IMAPClient-2.1.4);
use lib qw(/home/hasting/scripts/HELP/PERL/mod/Mail-Audit-Attach-0.93);
use lib qw(/home/hasting/scripts/HELP/PERL/mod/Mail-Audit-2.1);
use lib qw(/home/hasting/scripts/HELP/PERL/mod/MailTools-1.15);
use lib qw(/home/hasting/scripts/HELP/PERL/mod/IO-Socket-SSL-0.94);
use Mail::IMAPClient;
use Mail::Audit qw(Attach);
use IO::Socket::SSL;
my $server='';
my $port=993;
my $username='';
my $password='';
my $ssl = IO::Socket::SSL->new(Proto=>'tcp',
SSL_verify_mod=>0x00,
PeerAddr=>$server,
PeerPort=>$port);
my $imap = Mail::IMAPClient->new(Socket=>$ssl,User=>$username, Password
=>$password, Peek=>1);
$imap->State($imap->Connected);
$imap->login();
$imap->select('INBOX');
my $flaghash=$imap->flags(scalar($imap->search("ALL")));
for my $id (sort keys %$flaghash) {
my @data=split(/\n/, $imap->message_string($id));
my $mail=Mail::Audit->new(data=>\@data);
my $attachments=$mail->attachments;
my $from=$mail->Mail::Audit::from;
my $subject=$mail->Mail::Audit::subject;
print "$from $subject\n";
print "########################\n";
}
$imap->close();
------------------------------
Date: Wed, 30 Jul 2003 21:12:34 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Read from SSL IMAP
Message-Id: <20030730171414.5d47369e.jwillmore@cyberia.com>
> ---sample code
> --note, I am not an admin, so I've installed the modules in the
> root home/hasting/scripts/HELP/PERL/mod/
> --note, I also edited the server, user, and password when testing,
> I just didn;t paste it here.
>
instead of:
> use lib
> qw(/home/hasting/scripts/HELP/PERL/mod/Mail-IMAPClient-2.1.4); use
> lib qw(/home/hasting/scripts/HELP/PERL/mod/Mail-Audit-Attach-0.93);
> use lib qw(/home/hasting/scripts/HELP/PERL/mod/Mail-Audit-2.1); use
> lib qw(/home/hasting/scripts/HELP/PERL/mod/MailTools-1.15); use lib
> qw(/home/hasting/scripts/HELP/PERL/mod/IO-Socket-SSL-0.94);
try:
BEGIN{
push @INC,'/home/hasting/scripts/HELP/PERL/mod';
}
I have the same situation at work. One important note - some modules
require that a core Perl module be upgraded, so you may get so far
with installing modules until you have to ask an admin for assistance.
HTH
Jim
------------------------------
Date: Wed, 30 Jul 2003 15:31:48 -0600
From: Eric Schwartz <emschwar@ldl.fc.hp.com>
Subject: Re: Read from SSL IMAP
Message-Id: <eto7k5zbt17.fsf@wormtongue.emschwar>
James Willmore <jwillmore@cyberia.com> writes:
> try:
>
> BEGIN{
> push @INC,'/home/hasting/scripts/HELP/PERL/mod';
> }
This is equivalent to
use lib '/home/hasting/scripts/HELP/PERL/mod';
which is more idiomatic Perl.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 30 Jul 2003 17:37:23 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: remote readdir()
Message-Id: <u9he54ged8.fsf@wcl-l.bham.ac.uk>
Martien Verbruggen <mgjv@tradingpost.com.au> writes:
> On 29 Jul 2003 10:30:09 -0700,
> ARod <Arthurkog@yahoo.com> wrote:
>
> > $remote = "\\\\server\\some_share";
>
> Don't use double quotes for this, use singles, unless you like
> repeating all those backslashes.
Well, I _do_ like repeating all those backslashes.
Or rather, given that I'm going to have to repeat some of them I'd
rather repeat then all.
$remote = "\\\\server\\some_share"; # Works but ugly
$remote = '\\server\some_share'; # Looks nice, but doesn't work
$remote = '\\\\server\some_share'; # Works but even uglier than ""
$remote = '//server/some_share'; # Much nicer(1)
(1) but may not work if passing $remote to some external programs.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 30 Jul 2003 09:25:29 -0700
From: tonyw@shelter.org.uk (Tony W)
Subject: removing some text
Message-Id: <f810cf78.0307300825.404670eb@posting.google.com>
Hello,
I know nothing about perl but have a perl script that I need to
modify.
The line below removes all web links but leaves the text in the file.
# Remove existing glossary links
$newbody =~ s/<A HREF=\"Javascript\:popup\('[0-9]+',[^>]*>([^<]*)<\/A>/$1/ig;
eg. Starts with this:
<a href="JavaScript:popup('104',380,460);" class="results">rent in
advance</a>
ends with this:
rent in advance
I don't really understand the code but I know that all current links
are in the format that I've shown in the example above.
I want a line that will remove any a href link, except for the term
(eg landlords - as below)
<a href="/privrent/landlordresps-360-Een-f0.cfm"
class="results">Landlords</a>
------------------------------
Date: Wed, 30 Jul 2003 17:17:57 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: removing some text
Message-Id: <slrnbifve5.bvu.trammell+usenet@hypersloth.el-swifto.com.invalid>
On 30 Jul 2003 09:25:29 -0700, Tony W <tonyw@shelter.org.uk> wrote:
> Hello,
>
> I know nothing about perl but have a perl script that I need to
> modify.
>
[request to strip HTML tags removed]
"How do I remove HTML from a string?"
This is a FAQ. Read the FAQ. Love the FAQ.
http://perldoc.com/perl5.8.0/pod/perlfaq9.html
http://theoryx5.uwinnipeg.ca/CPAN/data/HTML-Strip/Strip.html
------------------------------
Date: 30 Jul 2003 18:14:13 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: removing some text
Message-Id: <u94r14gcnu.fsf@wcl-l.bham.ac.uk>
tonyw@shelter.org.uk (Tony W) writes:
> I know nothing about perl but have a perl script that I need to
> modify.
The standard reply is to need to either learn Perl or hire a Perl
programmer.
> The line below removes all web links but leaves the text in the file.
No very reliably. See FAQ: "How do I remove HTML from a string?"
> # Remove existing glossary links
> $newbody =~ s/<A HREF=\"Javascript\:popup\('[0-9]+',[^>]*>([^<]*)<\/A>/$1/ig;
>
> eg. Starts with this:
> <a href="JavaScript:popup('104',380,460);" class="results">rent in
> advance</a>
>
> ends with this:
> rent in advance
>
> I don't really understand the code but I know that all current links
> are in the format that I've shown in the example above.
>
> I want a line that will remove any a href link, except for the term
> (eg landlords - as below)
>
> <a href="/privrent/landlordresps-360-Een-f0.cfm"
> class="results">Landlords</a>
A simple HTML::Filter should do that.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 30 Jul 2003 13:41:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: removing some text
Message-Id: <slrnbig4bm.7vr.tadmc@magna.augustmail.com>
Tony W <tonyw@shelter.org.uk> wrote:
> The line below removes all web links but leaves the text in the file.
> # Remove existing glossary links
> $newbody =~ s/<A HREF=\"Javascript\:popup\('[0-9]+',[^>]*>([^<]*)<\/A>/$1/ig;
^ ^
^ ^
Neither of those backslashes are needed, making the experience
level of whoever wrote this code questionable...
> eg. Starts with this:
><a href="JavaScript:popup('104',380,460);" class="results">rent in
> advance</a>
> I know that all current links
> are in the format that I've shown in the example above.
That is a profoundly important caveat.
It is the one that lets you ignore the usual response to your
"remove HTML" FAQ.
> I want a line that will remove any a href link, except for the term
> (eg landlords - as below)
>
><a href="/privrent/landlordresps-360-Een-f0.cfm"
^^^^^
^^^^^ where is the "Javascript:popup" part?
> class="results">Landlords</a>
So, you want to remove all <a> tags for <a> tags formated as in that
first one, and you don't care if it is easily broken by legal HTML?
With all of that out of the way, then you might try doing
it with a regex.
But your problem specification is wrong somewhere, the pattern above
should *already* be leaving that Landlords one alone, it does not
have "JavaScript" in it...
---------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
$_ = q(
<a href="JavaScript:popup('104',380,460);" class="results">rent in advance</a>
<a href="JavaScript:popup('104',380,460);" class="results">Landlords</a>
<a href="JavaScript:popup('104',380,460);" class="results">rent in advance</a>
);
s/(<A HREF="Javascript:popup\('[0-9]+',[^>]*>([^<]*)<\/A>)/
$2 eq 'Landlords' ? $1 : $2
/ige;
print;
---------------------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 30 Jul 2003 10:51:33 -0700
From: djbitchpimp@snowboard.com (Greg)
Subject: Re: split alternative using regexp?
Message-Id: <7e312ede.0307300951.7cce333b@posting.google.com>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my ($string, @array);
>
> $string = "This is a looong sentence ";
> @array = ( $string =~ m/\w+/g ) ;
>
> print join ( "\n", @array );
Sweet thanks guys. That was exactly what I was looking for. Now I am
trying to join the sentences back together using regexps. Is there any
way to do this (possibly using the ($'))?
Thanks again,
-Greg
------------------------------
Date: Wed, 30 Jul 2003 18:08:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: weird "perl -e" behaviour
Message-Id: <3F2809E7.ACCCA630@acm.org>
Francois Wisard wrote:
>
> I encounter a strange "perl -e" behaviour since I'm running FreeBSD 5.1
> (Perl 5.6.1). My one-liners are refused with strange error messages.
>
> Some examples:
>
> bash-2.05b$ perl -e "@a=('a'..'z');print $a[5]"
> ARRAY(0x810115c)bash-2.05b$
>
> or
>
> bash-2.05b$ perl -e "$_="abc";s/b/c/g;print $_"
> Undefined subroutine &main::ls called at -e line 1.
>
> or even
>
> bash-2.05b$ perl -e "@a=('a'..'z');print $#a"
> Bareword found where operator expected at -e line 1, near "0a"
> (Missing operator before a?)
> syntax error at -e line 1, next token ???
>
> Anyone knows what happens there? I'm tired of writing files when a
> one-liner should have sufficed.
Enclosing the argument for -e in double quotes will allow the shell to
interpolate the argument, use single quotes instead.
bash-2.05b$ perl -e '@a=("a".."z");print $a[5]'
bash-2.05b$ perl -e '$_="abc";s/b/c/g;print $_'
bash-2.05b$ perl -e '@a=("a".."z");print $#a'
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 30 Jul 2003 16:43:34 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Win32 Ole
Message-Id: <3F27F643.761D2DAD@earthlink.net>
Bart Lateur wrote:
> On my system, line 29 reads
>
> eval <<'OVERLOAD';
>
> The equivalent end delimiter is on line 33... It should just be the word
> "OVERLOAD" on its own line, with no additional whitespace around it,
> whatsoever. I think that is not the case.
I got the OLE.pm module again and now my line 29 is also
eval <<'OVERLOAD';
OVERLOAD
is alone there on line 33.
I also got the example again (shown below).
Now when I run Excel.pl is says:
"Win32/OLE.pm did not return a true value at Excel.pl line 4.
BEGIN failed--compilation aborted at Excel.pl line 4."
Of course line 4 is: use Win32::OLE;
I did a google search and came up with quite a bit of stuff,
but can't fix the problem. I think it just doesn't see the
module now, but I'm not sure.
_________________________________
use strict;
use warnings;
use Win32::OLE;
# use existing instance if Excel is already running
eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $ex) {
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";
}
# get a new workbook
$book = $ex->Workbooks->Add;
# write to a particular cell
$sheet = $book->Worksheets(1);
$sheet->Cells(1,1)->{Value} = "foo";
# write a 2 rows by 3 columns range
$sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ],
[ 42, 'Perl', 3.1415 ]];
# print "XyzzyPerl"
$array = $sheet->Range("A8:C9")->{Value};
for (@$array) {
for (@$_) {
print defined($_) ? "$_|" : "<undef>|";
}
print "\n";
}
# save and exit
$book->SaveAs( 'test.xls' );
undef $book;
undef $ex;
------------------------------
Date: Wed, 30 Jul 2003 18:08:42 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Win32 Ole
Message-Id: <l12giv0ebs8nujilfns36939bol7eg5pob@4ax.com>
Mike Flannigan wrote:
>I got the OLE.pm module again and now my line 29 is also
>eval <<'OVERLOAD';
>
>OVERLOAD
>is alone there on line 33.
Line 29 is the line with the "<<" on it. That's the start of the
quoting.
>
>I also got the example again (shown below).
>Now when I run Excel.pl is says:
>"Win32/OLE.pm did not return a true value at Excel.pl line 4.
>BEGIN failed--compilation aborted at Excel.pl line 4."
I really wonder how you get your modules... You're not using PPM to
install the module?
All modules and other required files ("use" is built on top of
"require") need to end in a true value. Usually it's a single "1;" on a
line of its own at the logical end of the file. If you cut it out,
please don't. Anyway you must have done something wacky to the source of
the module.
You can retrieve the modules from a subdirectory of
<http://ppm.activestate.com/PPMpackages/>. To iinstall a module with
PPM, you need a .ppd file and in the proper relative location, a .tar.gz
file. The .ppd file is a decription of what the module is and how to get
at it; the .tar.gz file is the actual archive -- openable with WinZIP,
if you must. OTOH, PPM is smart enough to retrieve the modules
themselves from the website, if you have an internet connection.
--
Bart.
------------------------------
Date: Wed, 30 Jul 2003 18:37:13 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Win32 Ole
Message-Id: <3F2810E3.D726D249@earthlink.net>
Bart Lateur wrote:
> Line 29 is the line with the "<<" on it. That's the start of the
> quoting.
>
>
> I really wonder how you get your modules... You're not using PPM to
> install the module?
>
> All modules and other required files ("use" is built on top of
> "require") need to end in a true value. Usually it's a single "1;" on a
> line of its own at the logical end of the file. If you cut it out,
> please don't. Anyway you must have done something wacky to the source of
> the module.
>
> You can retrieve the modules from a subdirectory of
> <http://ppm.activestate.com/PPMpackages/>. To iinstall a module with
> PPM, you need a .ppd file and in the proper relative location, a .tar.gz
> file. The .ppd file is a decription of what the module is and how to get
> at it; the .tar.gz file is the actual archive -- openable with WinZIP,
> if you must. OTOH, PPM is smart enough to retrieve the modules
> themselves from the website, if you have an internet connection.
Arggg. I thought I had it this time, but I'm kinda going in circles.
I got the Win32-OLE.zip file from that site. Installed it with:
ppm install Win32-OLE.ppd
Now when I run my Excel.pl script is says:
"Can't call method "Workbooks" on an undefined value at
excel.pl line 15.
Line15 is:
my $book = my $ex->Workbooks->Add;
I'm on a Win2000 box.
I have tried so many combinations of putting in and
removing "my" that I'm getting goofy :-)
One more time, here is the whole code of Excel.pl:
use strict;
use warnings;
use Win32::OLE;
# use existing instance if Excel is already running
eval {my $ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined my $ex) {
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";
}
# get a new workbook
my $book = my $ex->Workbooks->Add;
# write to a particular cell
my $sheet = $book->Worksheets(1);
$sheet->Cells(1,1)->{Value} = "foo";
# write a 2 rows by 3 columns range
$sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ],
[ 42, 'Perl', 3.1415 ]];
# print "XyzzyPerl"
my $array = $sheet->Range("A8:C9")->{Value};
for (@$array) {
for (@$_) {
print defined($_) ? "$_|" : "<undef>|";
}
print "\n";
}
# save and exit
$book->SaveAs( 'test.xls' );
undef $book;
undef $ex;
------------------------------
Date: Wed, 30 Jul 2003 18:10:12 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: zero but true?
Message-Id: <te2giv4rm2sh9s0t1hhk2795oe3u1k5fmq@4ax.com>
bill wrote:
>$ perl -e 'print "$]: ", 0E0 ? "OK\n" : "not OK\n"'
>5.008: not OK
>
>Isn't 0E0 supposed to evaluate to true?
Only as a string.
print "0E0" ? "true" : "false";
Conversion to a number will make it zero, "0", thus false.
--
Bart.
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5294
***************************************