[31041] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2286 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 20 16:09:47 2009

Date: Fri, 20 Mar 2009 13:09: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           Fri, 20 Mar 2009     Volume: 11 Number: 2286

Today's topics:
        Can Net::IMAP::Simple or Net::POP3 be used with Email:: <r.ted.byers@gmail.com>
        Confusion in perlrun documentation <schaitan@gmail.com>
    Re: Confusion in perlrun documentation <Peter@PSDT.com>
    Re: Confusion in perlrun documentation <schaitan@gmail.com>
    Re: DateTime format of date <tadmc@seesig.invalid>
    Re: DateTime format of date <justin.0903@purestblue.com>
    Re: How can I keep LWP::UserAgent from adding the http- <tadmc@seesig.invalid>
    Re: How can I keep LWP::UserAgent from adding the http- <glex_no-spam@qwest-spam-no.invalid>
    Re: how to extract bunch of things from ( ) <glennj@ncf.ca>
    Re: how to extract bunch of things from ( ) <glennj@ncf.ca>
    Re: how to extract bunch of things from ( ) <cartercc@gmail.com>
        is anybody using perl for mobile devices? <rabbits77@my-deja.com>
        Perl 5.10 and DBD::mysql <cartercc@gmail.com>
    Re: Perl 5.10 and DBD::mysql <r.ted.byers@gmail.com>
    Re: Perl 5.10 and DBD::mysql <cartercc@gmail.com>
    Re: Perl 5.10 and DBD::mysql <r.ted.byers@gmail.com>
    Re: Perl 5.10 and DBD::mysql <cartercc@gmail.com>
        use warnings unless $foo <sensorflo@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 20 Mar 2009 09:38:05 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Can Net::IMAP::Simple or Net::POP3 be used with Email::MIME::Attachment::Stripper?
Message-Id: <8a1acecd-1208-4673-8fbb-3962872db69b@l38g2000vba.googlegroups.com>

I get emails with data from a couple different sources, one of which
includes the data in plain text in the body of the message and the
other provides it in Excel spreadsheets attached to the email.

I have been able to use Net::IMAP::Simple to get unseen messages and
parse the message text to retrieve the data I require from the one
data source, and I have also used Net::POP3 successfully to get the
same email messages from the same server (which supports POP3, IMAP
and MS Exchange), but haven't been able to get the latter to tell me
which messages have been seen.  However, I am at a loss to figure out
how to either get it to tell me if a given message is a multipart
message or how to pass the messages I get from it to
Email::MIME::Attachment::Stripper in order to use it to get the
attachements.  As I already have code to process these files, all I
really need to do is detect when a message includes attachements and
when that happens save the file to a suitable directory (which would
have a name computed and then be created to hold the files).

The documentation for Net::IMAP::Simple and Net::POP3 does not give
any clues as to how to convert the messages they let you retrieve into
something Email::MIME::Attachment::Stripper can work with.

So what is the piece I have missed that is necessary to finish this
last piece of this puzzle?

Thanks

Ted


------------------------------

Date: Fri, 20 Mar 2009 04:49:20 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Confusion in perlrun documentation
Message-Id: <a7f45401-c075-4878-949e-59f24011ec44@v13g2000pro.googlegroups.com>

Hi, I've been trying out a2p and found these lines at the top of the
perl output:

#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;

Googled around for this and found several links to perlrun that
attempt to explain what this idiom does exactly but I am confused
about the part where the shell exec's /usr/bin/perl with the script
name and its arguments and then .... "ignores the lines parsed from
the script because the $running_under_some_shell variable is always
false"....

Where is the glue between parsing lines and ignoring them due to this
undefined variable? How is this happening exactly? Could anyone please
explain in a simpler language what is happening?

Thanks...


------------------------------

Date: Fri, 20 Mar 2009 14:33:12 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Confusion in perlrun documentation
Message-Id: <IONwl.133206$EO2.117787@newsfe04.iad>

On Fri, 20 Mar 2009 04:49:20 -0700, Krishna Chaitanya wrote:

> Hi, I've been trying out a2p and found these lines at the top of the
> perl output:
> 
> #!/usr/bin/perl
> eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
>     if $running_under_some_shell;
> 
> Googled around for this and found several links to perlrun that attempt
> to explain what this idiom does exactly but I am confused about the part
> where the shell exec's /usr/bin/perl with the script name and its
> arguments and then .... "ignores the lines parsed from the script
> because the $running_under_some_shell variable is always false"....
> 
> Where is the glue between parsing lines and ignoring them due to this
> undefined variable? How is this happening exactly? Could anyone please
> explain in a simpler language what is happening?

This construct is meant for ancient systems that don't know what #!
means and pass every script to /bin/sh.  (Anyone know whether any such
systems are still in use?)

The lines are written so that they do the right thing in both /bin/sh
and perl.  When /bin/sh reads the first line, it interprets it as
meaning, "run perl on this file and pass it the arguments I was given",
which is what you want.  When perl runs the file - whether because it
was started on it originally due to being on a nonbroken system or whether 
because it was started by the eval line - it reads the eval line but being 
perl, then reads the next line to see the rest of the statement, and 
ignores it because $running_under_some_shell was never set and is 
therefore undef, hence false.  Then it goes on with the rest of the 
program.

HTH.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274


------------------------------

Date: Fri, 20 Mar 2009 08:11:26 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Confusion in perlrun documentation
Message-Id: <8dde05ab-5006-4e21-9c95-ccc63d1f427c@p6g2000pre.googlegroups.com>

So...if I get it correctly:

In case of an antique system, /bin/sh executes Perl interpreter
through 'exec' which replaces the /bin/sh process (being an 'exec')
and becomes a Perl program instead. In the Perl program now, it looks
at the eval statement again with the statement modifier having
$running_under_some_shell which is undef (therefore false) and skips
the eval. And continues running the rest of the Perl code in $0?




------------------------------

Date: Fri, 20 Mar 2009 07:58:21 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: DateTime format of date
Message-Id: <slrngs74nd.so6.tadmc@tadmc30.sbcglobal.net>

Justin C <justin.0903@purestblue.com> wrote:
> On 2009-03-18, Glenn Jackman <glennj@ncf.ca> wrote:
>> At 2009-03-18 10:21AM, "Justin C" wrote:
>>>  I need to output the date as six digits DDMMYY, with leading zeros where
>>>  necessary, and only the last two digits of the year. 


>>>  use POSIX;
>>>  use DateTime;


>>>  Is there a 'cleaner' way, just using the DateTime module?
>>
>> Do you /need/ to use DateTime for this?  You're already using POSIX, so
>
> No, I don't need to use DateTime, and POSIX slipped in in error, I was
> reading the DateTime docs, got to strftime and got confused. I
> understood it as time input rather than output.
>
>
>>     my $formattedDate = strftime "%d%m%y", localtime; 
>
> Works perfectly, thank you. But I'm not sure what's going on.


Glenn's code uses the "strftime" subroutine provided by the POSIX module.


> strftime = STRing Formatting of TIME? 


Right.


> ... and why is the documentation for it in DateTime 


It isn't.


> when you don't need
> the DateTime module for it to run? 


DateTime also defines something that happens to be named "strftime".

The documentation for DateTime documents the strftime that it provides.

The documentation for POSIX documents the strftime that it provides.

Which documentation applies is determined by which strftime()
you are using.


> There's obviously still a *lot* for
> me to learn.


It appears that you should learn a bit about packages, modules
and exporting of symbols into the main:: namespace. Start with:

    perldoc perlmod


You can get the same output as from the POSIX module if you use
DateTime correctly:

--------------------------
#!/usr/bin/perl
use warnings;
use strict;
use DateTime; # exports nothing because it is object oriented

my $dt = DateTime->now();  # need a DateTime object to use DateTime module
my $dt_formattedDate = $dt->strftime("%d%m%y");
print "DateTime: $dt_formattedDate\n";
--------------------------

Your code has

    use POSIX;

which will import lots (over 500 of them!) of symbols into the
main (global) namespace. Let's find out exaclty how many
(see the "Symbol Tables" section in perlmod.pod):

--------------------------
#!/usr/bin/perl
use warnings;
use strict;

BEGIN {
    $_ = keys %main::;
    warn "before: $_\n";
}

use POSIX;

BEGIN {
    $_ = keys %main::;
    warn "after: $_\n";
}
--------------------------


Importing hundreds of names into the global namespace like that is 
a Very Bad Idea. So you should avoid using just "use POSIX;".

You can either import only the symbols (names) that you plan to use:

--------------------------
#!/usr/bin/perl
use warnings;
use strict;
use POSIX 'strftime'; # exports 1 symbol

my $posix_formattedDate = strftime "%d%m%y", localtime; 
print "POSIX   : $posix_formattedDate\n";
--------------------------

Or, even better, import NO symbols and use the fully-qualified name instead:

--------------------------
#!/usr/bin/perl
use warnings;
use strict;
use POSIX (); # exports no symbols because we told it not to

my $posix_formattedDate = POSIX::strftime "%d%m%y", localtime; 
print "POSIX   : $posix_formattedDate\n";
--------------------------


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Fri, 20 Mar 2009 14:10:15 -0000
From: Justin C <justin.0903@purestblue.com>
Subject: Re: DateTime format of date
Message-Id: <1a0e.49c3a3c7.10003@zem>

On 2009-03-20, Tad J McClellan <tadmc@seesig.invalid> wrote:

[big snippage]
>
> It appears that you should learn a bit about packages, modules
> and exporting of symbols into the main:: namespace. Start with:
>
>     perldoc perlmod

[more big snippage]

I've read it, I even understand some of it. But I've left it as 'unread'
because I definitely need to come back to it.

I agree, I do need a better understanding of modules, especially as I've
written a couple... and they work (do not ask me how, really, I don't
know). So this looks like as good a time as any to take another step
forward in my Perl eddycation.

Thanks for the post. Though I'm not sure I'll thank you when I start
getting bogged down in the docs!

	Justin.

-- 
Justin C, by the sea.


------------------------------

Date: Fri, 20 Mar 2009 13:06:15 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How can I keep LWP::UserAgent from adding the http-equiv strings  from the Head section of the page?
Message-Id: <slrngs7mon.79o.tadmc@tadmc30.sbcglobal.net>

J. Gleixner <glex_no-spam@qwest-spam-no.invalid> wrote:
> CronJob wrote:


>>   my $ua = new LWP::UserAgent;
>
> my $ua = LWP::UserAgent->new();

>>   my $request = new HTTP::Request($method, $path);
>
> my $request = HTTP::Request->new( $method, $path );


Just in case you're wondering why this suggested change is
a Really Good Idea, see the "Indirect Object Syntax" section in:

   perldoc perlobj


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Fri, 20 Mar 2009 12:17:55 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: How can I keep LWP::UserAgent from adding the http-equiv strings from the Head section of the page?
Message-Id: <49c3cfc3$0$89864$815e3792@news.qwest.net>

CronJob wrote:
[...]
> Working code:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use LWP::UserAgent;
> use HTML::Parse;
> use HTML::Element;
> use HTTP::Response;
> use HTTP::Request;
> use HTTP::Status;
> use URI::URL;

Some minor tweaks..


Do you really need all of those?

> 
> my $ie7UAString = 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)';
> my ($code, $desc, $headers,$body) = &LWPUserAgentRequest('GET','http://www.google.com');

Remove the '&'------------------------^

If you add a '/' to the end of the URL, then the Web server doesn't
have to do it for you.

> print "The headers:\n$headers\n";
> print "The body:\n$body\n";

You can call print once, with a list:

print "The headers:\n$headers\n",
       "The body:\n$body\n";
> 
> sub LWPUserAgentRequest {
>   my ($method, $path) = @_;

Usually, it's nice to have a blank line after initializing
the input parameters.

>   my $ua = new LWP::UserAgent;

my $ua = LWP::UserAgent->new();

>   $ua->agent($ie7UAString);
>   $ua->parse_head(0);
>   my $request = new HTTP::Request($method, $path);

my $request = HTTP::Request->new( $method, $path );

>   my $response = $ua->request($request);
>   my $body = $response->content;
>   $body = $response->error_as_HTML if ($response->is_error);

my $body = ( $response->is_error )
	? $response->error_as_HTML
	: $response->content;

>   my $code = $response->code;
>   my $desc = HTTP::Status::status_message($code);
>   my $headers = $response->headers_as_string;

Ya don't really need $headers, you could just return
$response->headers_as_string, instead of $headers, below.

>   return ($code, $desc, $headers, $body);
> }
> 


------------------------------

Date: 20 Mar 2009 15:54:22 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: how to extract bunch of things from ( )
Message-Id: <slrngs7f1f.ijf.glennj@smeagol.ncf.ca>

At 2009-03-19 07:48PM, "sherry" wrote:
>  I need to extract all the args from this line of code:
>  
>  foo3( "something %s", ( BYTE )arg1, arg2.m_pcContentLocation );
>  
>  the result is something like this:
>  
>  "something %s", ( BYTE )arg1, arg2.m_pcContentLocation


    use Text::Balanced 'extract_bracketed';
    $s = 'foo3( "something %s", ( BYTE )arg1, arg2.m_pcContentLocation );';
    $t = ( extract_bracketed($s, '()', '[^(]*') )[0];
    $t = substr($t, 1, -1);

-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous


------------------------------

Date: 20 Mar 2009 16:07:41 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: how to extract bunch of things from ( )
Message-Id: <slrngs7fqe.ijf.glennj@smeagol.ncf.ca>

At 2009-03-20 11:54AM, "Glenn Jackman" wrote:
>  At 2009-03-19 07:48PM, "sherry" wrote:
> >  I need to extract all the args from this line of code:
> >  
> >  foo3( "something %s", ( BYTE )arg1, arg2.m_pcContentLocation );
> >  
> >  the result is something like this:
> >  
> >  "something %s", ( BYTE )arg1, arg2.m_pcContentLocation
>  
>  
>      use Text::Balanced 'extract_bracketed';
>      $s = 'foo3( "something %s", ( BYTE )arg1, arg2.m_pcContentLocation );';
>      $t = ( extract_bracketed($s, '()', '[^(]*') )[0];
>      $t = substr($t, 1, -1);

Probably better is:

    use Regexp::Common 'balanced'
    $s = 'foo3( "something %s", ( BYTE )arg1, arg2.m_pcContentLocation );';
    if ($s =~ /$RE{balanced}{-parens=>'()'}{-keep}/) {
        $t = substr($1, 1, -1);
    }


-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous


------------------------------

Date: Fri, 20 Mar 2009 09:26:45 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: how to extract bunch of things from ( )
Message-Id: <b01a54a2-7418-4709-894a-b7dbf38620c4@p11g2000yqe.googlegroups.com>

CODE:
my $string = qq( "something %s", ( BYTE )arg1,
arg2.m_pcContentLocation );
my @vars = split /,/, $string;
foreach my $var (@vars) {print "$var\n";}

OUTPUT:
C:\PerlLearn>perl test.22.plx
 "something %s"
 ( BYTE )arg1
 arg2.m_pcContentLocation

C:\PerlLearn>


------------------------------

Date: Fri, 20 Mar 2009 13:25:28 -0400
From: rabbits77 <rabbits77@my-deja.com>
Subject: is anybody using perl for mobile devices?
Message-Id: <3da8b$49c3d185$c650990a$10714@news.eurofeeds.com>

I am curious to see if it is possible to use perl
to develop for mobile devices. Googling has revealed to
me a very old stab at perl for Symbian phone.
There are a couple of other tries here and there
but they are all very old and seem to not be maintained
and provide no documentation or examples.
Does anyone here know of any actively maintained perl SDKs
for mobile devices?


------------------------------

Date: Fri, 20 Mar 2009 08:10:11 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Perl 5.10 and DBD::mysql
Message-Id: <fe1d6548-9a7d-4847-936e-c53065e0e9fc@h28g2000yqd.googlegroups.com>

I've been using DBD::mysql ever since Perl 5.0 and never had a problem

I'm now using Perl 5.10 on a brand new Windows Vista machine and for
the life of me cannot get DBD::mysql either through ppm or cpan. I got
mysqlPP but that doesn't do some of the things I need to do.

Any suggestions? Thanks, CC.


------------------------------

Date: Fri, 20 Mar 2009 09:21:37 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Perl 5.10 and DBD::mysql
Message-Id: <bf96d797-4b4b-49aa-bb35-81a353a1d819@r16g2000vbp.googlegroups.com>

On Mar 20, 11:10=A0am, ccc31807 <carte...@gmail.com> wrote:
> I've been using DBD::mysql ever since Perl 5.0 and never had a problem
>
> I'm now using Perl 5.10 on a brand new Windows Vista machine and for
> the life of me cannot get DBD::mysql either through ppm or cpan. I got
> mysqlPP but that doesn't do some of the things I need to do.
>
> Any suggestions? Thanks, CC.

Did you add the university of Winnipeg repository (in PPM, select edit/
preferences)?  If not, do so and then you'll find DBD::mysql.

As there are some differences between repositories, you might as well
add all of the repositories that Activestate provides in the dropdown
list they provide to make such additions easy.

Cheers,

Ted


------------------------------

Date: Fri, 20 Mar 2009 09:46:36 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Perl 5.10 and DBD::mysql
Message-Id: <78d8083c-566a-44b5-ae18-d3ab2f471281@v19g2000yqn.googlegroups.com>

On Mar 20, 12:21=A0pm, Ted Byers <r.ted.by...@gmail.com> wrote:
> Did you add the university of Winnipeg repository (in PPM, select edit/
> preferences)? =A0If not, do so and then you'll find DBD::mysql.

If I were a cussing man, I'd cuss. I have an iteration of a project
due tonight on this new machine, and dad-blast-it, they don't make it
easy, do they? Thanks for your help, and it was easy, but only if you
knew how to begin with. As it is, I wasted the better part of Thursday
and Friday trying to get this to work, and it should have worked out
of the box.

> As there are some differences between repositories, you might as well
> add all of the repositories that Activestate provides in the dropdown
> list they provide to make such additions easy.

Good advice, and I'll do it.

> Cheers,

Cheers to you. If I knew you, I'd buy you a bottle of your favorite
beverage, and feel that I got much the better end of the bargain.
Thanks, CC.


------------------------------

Date: Fri, 20 Mar 2009 09:53:19 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Perl 5.10 and DBD::mysql
Message-Id: <e7da8a8f-15e6-46e9-a0a9-bf4cb2fa344f@l38g2000vba.googlegroups.com>

On Mar 20, 12:46=A0pm, ccc31807 <carte...@gmail.com> wrote:
> Cheers to you. If I knew you, I'd buy you a bottle of your favorite
> beverage, and feel that I got much the better end of the bargain.
> Thanks, CC.

I don't drink anything but coffee, but how about, in  lieu of a drink
for me, you send a small donation to your nearest food bank to help
someone who has suffered because of these interesting economic times.

I'm just glad I could help.

Cheers

Ted


------------------------------

Date: Fri, 20 Mar 2009 10:23:41 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Perl 5.10 and DBD::mysql
Message-Id: <d2dc508a-60a5-4db6-bb21-794399c345f7@y13g2000yqn.googlegroups.com>

On Mar 20, 12:53=A0pm, Ted Byers <r.ted.by...@gmail.com> wrote:
> I don't drink anything but coffee, but how about, in =A0lieu of a drink
> for me, you send a small donation to your nearest food bank to help
> someone who has suffered because of these interesting economic times.

I'll do that.

> I'm just glad I could help.

So am I.

CC


------------------------------

Date: Fri, 20 Mar 2009 13:08:10 -0700 (PDT)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: use warnings unless $foo
Message-Id: <53fe0fcb-e404-47e1-a113-445546769d0d@e35g2000yqc.googlegroups.com>

use, no, package are special in that I can not say

use warnings if $foo;

Is there a name for those keywords which do not form a normal
expression? I.e. where I can not append a statement modifier.

Where in the perldoc do I find a complete list of those keywords?

Thank you

Flo


------------------------------

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 V11 Issue 2286
***************************************


home help back first fref pref prev next nref lref last post