[31643] in Perl-Users-Digest
Perl-Users Digest, Issue: 2906 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 8 21:09:25 2010
Date: Thu, 8 Apr 2010 18:09:09 -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 Thu, 8 Apr 2010 Volume: 11 Number: 2906
Today's topics:
Re: FAQ 3.4 How do I find which modules are installed o <peter@www.pjb.com.au>
Re: FAQ 3.4 How do I find which modules are installed o <brian.d.foy@gmail.com>
Re: FAQ 3.4 How do I find which modules are installed o <stevem_clipthis_@clubtrout.com>
Re: FAQ 3.4 How do I find which modules are installed o <uri@StemSystems.com>
Re: FAQ 3.4 How do I find which modules are installed o <glex_no-spam@qwest-spam-no.invalid>
Re: FAQ 3.4 How do I find which modules are installed o <stevem_clipthis_@clubtrout.com>
Perl 5.8 RE for fixed string with an optional colon ter <RedGrittyBrick@spamweary.invalid>
Re: Perl 5.8 RE for fixed string with an optional colon <uri@StemSystems.com>
Re: Perl 5.8 RE for fixed string with an optional colon sln@netherlands.com
Re: Perl 5.8 RE for fixed string with an optional colon sln@netherlands.com
Re: Perl 5.8 RE for fixed string with an optional colon sln@netherlands.com
Re: Perl 5.8 RE for fixed string with an optional colon <RedGrittyBrick@spamweary.invalid>
Re: Perl 5.8 RE for fixed string with an optional colon <hhr-m@web.de>
Re: Perl 5.8 RE for fixed string with an optional colon <RedGrittyBrick@spamweary.invalid>
Re: Perl 5.8 RE for fixed string with an optional colon <hhr-m@web.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 08 Apr 2010 10:20:34 GMT
From: Peter Billam <peter@www.pjb.com.au>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <slrnhrrbfj.3mr.peter@box8.pjb.com.au>
On 2010-04-08, PerlFAQ Server <brian@theperlreview.com> wrote:
> 3.4: How do I find which modules are installed on my system?
> From the command line, you can use the "cpan" command's "-l" switch:
> $ cpan -l
Hmm... I'm running up-to-date debian squeeze,
/usr/bin/cpan script version 1.9, CPAN.pm version 1.9402,
and when I try that I just get:
box8> cpan -l
Unknown option: l
Nothing to install!
:-( Am I doing something wrong ?
Regards, Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
------------------------------
Date: Thu, 08 Apr 2010 13:28:17 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <080420101328178135%brian.d.foy@gmail.com>
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]
In article <slrnhrrbfj.3mr.peter@box8.pjb.com.au>, Peter Billam
<peter@www.pjb.com.au> wrote:
> On 2010-04-08, PerlFAQ Server <brian@theperlreview.com> wrote:
> > 3.4: How do I find which modules are installed on my system?
> > From the command line, you can use the "cpan" command's "-l" switch:
> > $ cpan -l
>
> Hmm... I'm running up-to-date debian squeeze,
> /usr/bin/cpan script version 1.9, CPAN.pm version 1.9402,
Check that you are using the latest cpan client. It's in App::Cpan on
CPAN.
------------------------------
Date: Thu, 08 Apr 2010 14:11:44 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <aKrvn.219961$Dv7.4545@newsfe17.iad>
On 4/8/2010 3:00 AM, PerlFAQ Server wrote:
> This is an excerpt from the latest version perlfaq3.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
>
> --------------------------------------------------------------------
>
> 3.4: How do I find which modules are installed on my system?
>
> From the command line, you can use the "cpan" command's "-l" switch:
>
> $ cpan -l
>
> You can also use "cpan"'s "-a" switch to create an autobundle file that
> "CPAN.pm" understands and can use to re-install every module:
>
> $ cpan -a
>
> Inside a Perl program, you can use the "ExtUtils::Installed" module to
> show all installed distributions, although it can take awhile to do its
> magic. The standard library which comes with Perl just shows up as
> "Perl" (although you can get those with "Module::CoreList").
>
> use ExtUtils::Installed;
>
> my $inst = ExtUtils::Installed->new();
> my @modules = $inst->modules();
>
> If you want a list of all of the Perl module filenames, you can use
> "File::Find::Rule":
>
> use File::Find::Rule;
>
> my @files = File::Find::Rule->
> extras({follow => 1})->
> file()->
> name( '*.pm' )->
> in( @INC )
> ;
>
> If you do not have that module, you can do the same thing with
> "File::Find" which is part of the standard library:
>
> use File::Find;
> my @files;
>
> find(
> {
> wanted => sub {
> push @files, $File::Find::fullname
> if -f $File::Find::fullname&& /\.pm$/
> },
> follow => 1,
> follow_skip => 2,
> },
> @INC
> );
>
> print join "\n", @files;
>
> If you simply need to quickly check to see if a module is available, you
> can check for its documentation. If you can read the documentation the
> module is most likely installed. If you cannot read the documentation,
> the module might not have any (in rare cases):
>
> $ perldoc Module::Name
>
> You can also try to include the module in a one-liner to see if perl
> finds it:
>
> $ perl -MModule::Name -e1
>
>
>
> --------------------------------------------------------------------
>
> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
> are not necessarily experts in every domain where Perl might show up,
> so please include as much information as possible and relevant in any
> corrections. The perlfaq-workers also don't have access to every
> operating system or platform, so please include relevant details for
> corrections to examples that do not work on particular platforms.
> Working code is greatly appreciated.
>
> If you'd like to help maintain the perlfaq, see the details in
> perlfaq.pod.
Often times I'm working on a web site for someone where I do not have
command line access, only web browser access, and I wish to check for
specific modules that are a little off the beaten path, such as
Spreadsheet::WriteExcel.
In such a case, the above examples are perhaps not as 'to the point' as
a reader might wish.
I use a different (simpler?) method than any shown above, and wonder if
it might be a good concept to include in the above options. In essence I
run something like below.
*********
To construct a simple CGI script to test for module availability when
the command line is not available, but you do have CGI capability:
#!/usr/bin/perl
use warnings;
$! = 1;
print "Content-type: text/html\n\n";
print qq~Testing for availability of Perl Modules<br><br>\n~;
my @test_list = (
'CGI',
'DBI',
'Spreadsheet::WriteExcel',
'Spreadsheet::ParseExcel',
);
for( @test_list ){
print qq~$_: ~;
eval "use $_; 1" ? ( print 'Available' ) : ( print 'MISSING!!!' );
print "<br>\n";
}
exit;
*************
I'm thinking someone trying to get their feet wet with CGI scripts might
find the above example to be more in line with what they can understand
or use and what they probably have available.
Or maybe not. :-)
\s
--
"There is no use in your walking five miles to fish when you can depend
on being just as unsuccessful near home." M. Twain
------------------------------
Date: Thu, 08 Apr 2010 18:06:55 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <87iq81egzk.fsf@quad.sysarch.com>
>>>>> "SM" == Steve M <stevem_clipthis_@clubtrout.com> writes:
SM> #!/usr/bin/perl
SM> use warnings;
why not strict too?
SM> $! = 1;
huh? i think you meant $| = 1. and that will not have any real affect
with such a short output and also with the buffering done by the
server.
SM> print "Content-type: text/html\n\n";
SM> print qq~Testing for availability of Perl Modules<br><br>\n~;
why are you using alternate quote chars when there are no quote chars
in the string? and if you do use alternate quotes, the best ones are the
paired chars. i use (and PBP recommends it too) q{} or qq{}.
SM> my @test_list = (
SM> 'CGI',
SM> 'DBI',
SM> 'Spreadsheet::WriteExcel',
SM> 'Spreadsheet::ParseExcel',
SM> );
SM> for( @test_list ){
SM> print qq~$_: ~;
no need for alternate quotes there.
SM> eval "use $_; 1" ? ( print 'Available' ) : ( print 'MISSING!!!' );
SM> print "<br>\n";
and that could all be done in one print:
print "$_: ",
( eval "use $_; 1" ) ? 'Available' : 'MISSING!!!',
"<br>\n";
a lot easier to see what you are doing that way. and no need for all
those extra print calls. also it removes the side effect thing inside ?:
which is bad style. ?: is meant to return a value, not choose which side
effect to execute.
but your concept is valid only if you have a lousy web service without a
shell. it is easier to switch services than to hack code only after you
ftp it there!
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 08 Apr 2010 17:12:05 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <4bbe54b6$0$89389$815e3792@news.qwest.net>
Steve M wrote:
[...]
> Often times I'm working on a web site for someone where I do not have
> command line access, only web browser access, and I wish to check for
> specific modules that are a little off the beaten path, such as
> Spreadsheet::WriteExcel.
>
> In such a case, the above examples are perhaps not as 'to the point' as
> a reader might wish.
>
> I use a different (simpler?) method than any shown above, and wonder if
> it might be a good concept to include in the above options. In essence I
> run something like below.
>
> *********
>
> To construct a simple CGI script to test for module availability when
> the command line is not available, but you do have CGI capability:
For that specific case, perldiver provides a lot of information
via a browser too.
------------------------------
Date: Thu, 08 Apr 2010 17:40:29 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <RNuvn.84269$9b5.13616@newsfe01.iad>
On 4/8/2010 3:06 PM, Uri Guttman wrote:
>>>>>> "SM" == Steve M<stevem_clipthis_@clubtrout.com> writes:
>
> SM> #!/usr/bin/perl
> SM> use warnings;
>
> why not strict too?
>
> SM> $! = 1;
>
> huh? i think you meant $| = 1. and that will not have any real affect
> with such a short output and also with the buffering done by the
> server.
>
I did mean $|.. have no idea how that got there.... And no, it won't
have any effect with the short example output... the list I use in real
life is considerably longer than the example I posted.
> SM> print "Content-type: text/html\n\n";
>
> SM> print qq~Testing for availability of Perl Modules<br><br>\n~;
>
> why are you using alternate quote chars when there are no quote chars
> in the string? and if you do use alternate quotes, the best ones are the
> paired chars. i use (and PBP recommends it too) q{} or qq{}.
Editor syntax color issue. It's undoubtedly poor style, but I shift back
and forth on quoting to make 'things' easier for my ancient eyes and
brain to parse.
>
> SM> my @test_list = (
> SM> 'CGI',
> SM> 'DBI',
> SM> 'Spreadsheet::WriteExcel',
> SM> 'Spreadsheet::ParseExcel',
> SM> );
>
> SM> for( @test_list ){
> SM> print qq~$_: ~;
>
> no need for alternate quotes there.
>
>
> SM> eval "use $_; 1" ? ( print 'Available' ) : ( print 'MISSING!!!' );
> SM> print "<br>\n";
>
> and that could all be done in one print:
>
> print "$_: ",
> ( eval "use $_; 1" ) ? 'Available' : 'MISSING!!!',
> "<br>\n";
>
> a lot easier to see what you are doing that way. and no need for all
> those extra print calls. also it removes the side effect thing inside ?:
> which is bad style. ?: is meant to return a value, not choose which side
> effect to execute.
True, does work though. Actually I rarely use a ternary quite that way.
>
> but your concept is valid only if you have a lousy web service without a
> shell. it is easier to switch services than to hack code only after you
> ftp it there!
>
> uri
>
Sigh... I agree up to a point on your last point.
However.
John or Jane Q. client comes to me with a programming job. They've been
with XYZ hosting company forever and XYZ does NOT provide shell access....
So, I tell them to change providers or I'll walk away from the job?
Nope.
\s
--
"There is no use in your walking five miles to fish when you can depend
on being just as unsuccessful near home." M. Twain
------------------------------
Date: Thu, 08 Apr 2010 15:39:04 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <4bbdea88$0$2493$db0fefd9@news.zen.co.uk>
I need to match fixed string FOO with an optional : terminated prefix
This doesn't work because the RE matches notFOO
for my $x (qw(FOO xxx:FOO yyy.FOO BAR notFOO FOOM)) {
if ($x =~ /^[^:]*:?FOO$/) {
print "Matched $x\n";
} else {
print "- $x\n";
}
}
Actual output:
Matched FOO
Matched xxx:FOO
Matched yyy.FOO
- BAR
Matched notFOO
- FOOM
Desired output:
Matched FOO
Matched xxx:FOO
Matched yyy.FOO
- BAR
- notFOO
- FOOM
xxx and yyy are just examples of \w+ excluding ':'
I've glanced at perlretut but would appreciate a clue.
--
RGB
------------------------------
Date: Thu, 08 Apr 2010 12:47:16 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <878w8xki23.fsf@quad.sysarch.com>
>>>>> "HR" == Helmut Richter <hhr-m@web.de> writes:
HR> On Thu, 8 Apr 2010, RedGrittyBrick wrote:
>> if ($x =~ /^[^:]*:?\bFOO$/) {
HR> That will still independetly check for optional [^:]* and optional
HR> : letting ,,,FOO pass. What you mean is probably
HR> /^([^:]+:)?\bFOO$/. Here I assumed that the part before the colon
HR> is nonempty if the colon is present.
i was going to suggest the grouping too. he says the whole prefix is
optional but he made the parts seperately optional instead. but now you
don't need the \b since if whole prefix is matched and it ends with :
and then sees FOO which means it always has a word boundary. also make
the group non-grabbing to speed it up unless he needs to grab the
prefix.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 08 Apr 2010 10:30:24 -0700
From: sln@netherlands.com
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <ks2sr5pv85pj9h0pshmeudktffvgo3gncm@4ax.com>
On Thu, 08 Apr 2010 15:39:04 +0100, RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote:
>I need to match fixed string FOO with an optional : terminated prefix
>
>This doesn't work because the RE matches notFOO
>
>for my $x (qw(FOO xxx:FOO yyy.FOO BAR notFOO FOOM)) {
> if ($x =~ /^[^:]*:?FOO$/) {
^^^^^^^^
This can't be generalized to be put together without alternation.
^ and [^:]*:? need to be alternatives as a prefix to FOO
Because it makes you have to say [^:]*:? and the quantifiers
* ? make posibile any char not :* zero or more times then :?
zero or one time.
This makes it too particular in its need to find : and results
in everything else not : getting by and matching. Even if you used
[.:] it wouldn't work.
From your own description, you positively are looking for only
2 things to match:
1. FOO all by itself
2. FOO prefixed by anything plus : or .
Thats the way you have to write the regexp.
Lets also asume that 1 and 2 above can be surrounded by optional
whitespace:
1. FOO all by itself
/ ^ \s* FOO \s* $ /x
2. FOO prefixed by anything plus : or .
/ .+[.:] FOO \s* $ /xs
Join them together via factoring:
/ (?: ^\s* | .+[.:] ) FOO \s* $/xs
> print "Matched $x\n";
> } else {
> print "- $x\n";
> }
>}
>
Matched () FOO
Matched (xxx:) xxx:FOO
Matched (yyy.) yyy.FOO
- BAR
- notFOO
- FOOM
-----------------------
use strict;
use warnings;
for my $x (qw(FOO xxx:FOO yyy.FOO BAR notFOO FOOM)) {
if ($x =~ / ( ^\s* | .+[.:] ) FOO \s* $/xs) {
print "Matched ($1) $x\n";
} else {
print "- $x\n";
}
}
__END__
-sln
------------------------------
Date: Thu, 08 Apr 2010 11:32:19 -0700
From: sln@netherlands.com
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <nl7sr51pj6b1skbvv58vrgnsfbc79g4hvr@4ax.com>
On Thu, 08 Apr 2010 15:39:04 +0100, RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote:
>I need to match fixed string FOO with an optional : terminated prefix
>
>This doesn't work because the RE matches notFOO
>
>for my $x (qw(FOO xxx:FOO yyy.FOO BAR notFOO FOOM)) {
> if ($x =~ /^[^:]*:?FOO$/) {
> print "Matched $x\n";
> } else {
> print "- $x\n";
> }
>}
>
Another possiblity:
Avoid having to describe everything preceeding FOO.
And, if you don't care about captureing all before FOO,
this should speed up the search/matching if you have
alot to parse.
use strict;
use warnings;
for my $x (qw(FOO :FOO xxx:FOO .FOO yyy.FOO BAR notFOO FOOM)) {
if ($x =~ / (?: ^ | (?<=[:.]) ) \s* FOO \s* $ /x) {
print "Matched $x\n";
print "Matched ($1) $x\n";
} else {
print "- $x\n";
}
}
---------------
Matched FOO
Matched :FOO
Matched xxx:FOO
Matched .FOO
Matched yyy.FOO
- BAR
- notFOO
- FOOM
------------------------------
Date: Thu, 08 Apr 2010 13:41:28 -0700
From: sln@netherlands.com
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <0resr59jm462e3nni1vd1lab37h8mo2fij@4ax.com>
On Thu, 8 Apr 2010 17:22:48 +0200, Helmut Richter <hhr-m@web.de> wrote:
>On Thu, 8 Apr 2010, RedGrittyBrick wrote:
>
>> if ($x =~ /^[^:]*:?\bFOO$/) {
>
>That will still independetly check for optional [^:]* and optional :
>letting ,,,FOO pass. What you mean is probably /^([^:]+:)?\bFOO$/.
>Here I assumed that the part before the colon is nonempty if the colon is
>present.
this - /^([^:]+:)?\bFOO$/
Indeed, grouping the the optional [^:]* and optional :
into a ()? took care of [^:]* letting ,,,FOO pass
However, by doing that, you don't let "prefix.FOO" pass.
This is why he had the :? independently optional so that
^[^:]*:?\bFOO$ would match 'prefix.FOO'
The \b protects the '.FOO' and the 'FOO' at the same time.
where [^:]*:? specifically matches 'prefix:FOO' and just so
happens : is compliant with \b and redundant.
Grouping changes the condition. Now \b won't find '.FOO'
because the search never consumes a '.'
This /^([^:]+:)?\bFOO$/ regexp at best is bloviated and redundant,
at worst will not match the conditions.
-sln
------------------------------
Date: Thu, 08 Apr 2010 15:44:53 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <4bbdebe5$0$2493$db0fefd9@news.zen.co.uk>
On 08/04/2010 15:39, RedGrittyBrick wrote:
> I need to match fixed string FOO with an optional : terminated prefix
>
> This doesn't work because the RE matches notFOO
>
> for my $x (qw(FOO xxx:FOO yyy.FOO BAR notFOO FOOM)) {
> if ($x =~ /^[^:]*:?FOO$/) {
if ($x =~ /^[^:]*:?\bFOO$/) {
> print "Matched $x\n";
> } else {
> print "- $x\n";
> }
> }
>
I knew I'd end up feeling stupid :-)
--
RGB
------------------------------
Date: Thu, 8 Apr 2010 17:22:48 +0200
From: Helmut Richter <hhr-m@web.de>
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <Pine.LNX.4.64.1004081719130.4401@lxhri01.lrz.lrz-muenchen.de>
On Thu, 8 Apr 2010, RedGrittyBrick wrote:
> if ($x =~ /^[^:]*:?\bFOO$/) {
That will still independetly check for optional [^:]* and optional :
letting ,,,FOO pass. What you mean is probably /^([^:]+:)?\bFOO$/.
Here I assumed that the part before the colon is nonempty if the colon is
present.
--
Helmut Richter
------------------------------
Date: Thu, 08 Apr 2010 17:45:49 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <4bbe083d$0$2532$da0feed9@news.zen.co.uk>
On 08/04/2010 16:22, Helmut Richter wrote:
> On Thu, 8 Apr 2010, RedGrittyBrick wrote:
>
>> if ($x =~ /^[^:]*:?\bFOO$/) {
>
> That will still independetly check for optional [^:]* and optional :
> letting ,,,FOO pass. What you mean is probably /^([^:]+:)?\bFOO$/.
Ah yes.
> Here I assumed that the part before the colon is nonempty if the colon is
> present.
Your assumption is correct.
Thanks
--
RGB
------------------------------
Date: Thu, 8 Apr 2010 21:48:08 +0200
From: Helmut Richter <hhr-m@web.de>
Subject: Re: Perl 5.8 RE for fixed string with an optional colon terminated prefix
Message-Id: <Pine.LNX.4.64.1004082147230.4187@lxhri01.lrz.lrz-muenchen.de>
On Thu, 8 Apr 2010, Uri Guttman wrote:
> HR> On Thu, 8 Apr 2010, RedGrittyBrick wrote:
> >> if ($x =~ /^[^:]*:?\bFOO$/) {
> i was going to suggest the grouping too. he says the whole prefix is
> optional but he made the parts seperately optional instead. but now you
> don't need the \b
Yes, of course. It remained from cut 'n paste.
--
Helmut Richter
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2906
***************************************