[30061] in Perl-Users-Digest
Perl-Users Digest, Issue: 1304 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 25 11:09:44 2008
Date: Mon, 25 Feb 2008 08:09:07 -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 Mon, 25 Feb 2008 Volume: 11 Number: 1304
Today's topics:
Re: BEGIN not safe after errors--compilation aborted <darrenbird@dipinternational.co.uk>
Re: BEGIN not safe after errors--compilation aborted <darrenbird@dipinternational.co.uk>
grep specific info from a file <gniagnia@gmail.com>
Re: grep specific info from a file <darthludi@gmail.com>
Re: How to get an account at cpan.org? <alodiaf@yahoo.de>
Re: How to get an account at cpan.org? <ben@morrow.me.uk>
new CPAN modules on Mon Feb 25 2008 (Randal Schwartz)
Problem using find on win32 <mikael.petterson@ericsson.com>
Session Expiration Problem <visitprakashindia@gmail.com>
Re: setting %ENV in a module <ben@morrow.me.uk>
Re: setting %ENV in a module <pgodfrin@gmail.com>
Re: Speeding my script <phynkel@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 25 Feb 2008 03:43:15 -0800 (PST)
From: daz9643 <darrenbird@dipinternational.co.uk>
Subject: Re: BEGIN not safe after errors--compilation aborted
Message-Id: <043c395c-5e0c-4ae5-8824-97d6c310db56@71g2000hse.googlegroups.com>
With ul class="simpleblue" removed all i get is,
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator,
darrenbird@dipinternational.co.uk and inform them of the time the
error occurred, and anything you might have done that may have caused
the error.
More information about this error may be available in the server error
log.
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use Time::HiRes qw(gettimeofday);
use URI::Escape;
------------------------------
Date: Mon, 25 Feb 2008 03:45:56 -0800 (PST)
From: daz9643 <darrenbird@dipinternational.co.uk>
Subject: Re: BEGIN not safe after errors--compilation aborted
Message-Id: <d2a87bbb-7324-4f57-a3f6-7a34478036ad@41g2000hsc.googlegroups.com>
This is what i've tried to follow to sort the problem, cut & pasted
from 123-reg.co.uk online support,
<p>If you encounter an error "500 Internal Server Error" whilst
running your CGI perl scripts, try the following in order:</p>
<ul class="simpleblue">
<li>Ensure you have uploaded the script through FTP using ASCII mode,
or that it has Unix-style carriage returns.</li>
<li>Check the perl interpreter on the first line of the script. It
should always be "#!/usr/bin/perl".</li>
<li>Make sure the script filename ends in either ".pl" or ".cgi".</li>
<li>Make sure the script can execute. It should have mode "0755". You
can change this in your file manager - set the mode to user read+write
+execute, group read+execute, other read+execute. Most FTP clients
also support this.</li>
<li>Put "use CGI::Carp qw(fatalsToBrowser);" into the second line of
your script. This will make perl print the error instead of the "500
Internal Server Error" page, and will allow you to find out where your
script is breaking.</li>
</ul>
------------------------------
Date: Mon, 25 Feb 2008 07:35:30 -0800 (PST)
From: Mr_Noob <gniagnia@gmail.com>
Subject: grep specific info from a file
Message-Id: <1763967b-43d9-473b-a3f3-f9fa04b46fe7@q70g2000hsb.googlegroups.com>
Hi all,
What is the best way to grep into a file, only lines beginning with
"[" and ending with "]" ?
And then, how can I feed an array with the information contained
between the 2 brackets, without the 2 brackets?
here is a sample of my file :
...
[blah blah blah]
some stuff here
[blabla again]
here is some other stuff here too
...
What I'd like to obtain is :
...
bla blah blah
blabla again
...
thanks in advance for ur help
Regards
------------------------------
Date: Mon, 25 Feb 2008 16:51:08 +0100
From: Peter Ludikovsky <darthludi@gmail.com>
Subject: Re: grep specific info from a file
Message-Id: <1203954726.781416@nntpcache01.si.eunet.at>
Mr_Noob wrote:
> Hi all,
>
> What is the best way to grep into a file, only lines beginning with
> "[" and ending with "]" ?
> And then, how can I feed an array with the information contained
> between the 2 brackets, without the 2 brackets?
>
> here is a sample of my file :
>
> ...
> [blah blah blah]
> some stuff here
>
> [blabla again]
> here is some other stuff here too
> ...
>
>
> What I'd like to obtain is :
>
> ...
> bla blah blah
> blabla again
> ...
>
>
> thanks in advance for ur help
> Regards
You mean something like this:
---SNIP---
#!/usr/bin/perl -W
use strict;
use warnings;
my @lines;
open INFILE,"<",$ARGV[0] or die "Can't open file: $!";
while(<INFILE>){
push @lines, $1 if /^\[(.+)\]$/;
}
close INFILE;
foreach (@lines){
print "$_\n";
}
---SNIP---
------------------------------
Date: Mon, 25 Feb 2008 08:59:52 +0100
From: "Alos Diaf" <alodiaf@yahoo.de>
Subject: Re: How to get an account at cpan.org?
Message-Id: <op.t62lt2haxx9xny@hope>
Ben Morrow <ben@morrow.me.uk>:
thanx Ben,
i want a cpan.org address, how to get it?
>
> Quoth "Alos Diaf" <alodiaf@yahoo.de>:
>>
>> wanna publish a module,
>> have to register at pause,
>> want to use a myname@cpan.org, who can i get such?
>
> See http://pause.perl.org/pause/query?ACTION=3Drequest_id .
> You need a (non-cpan) email address, but this can be completely privat=
e
> (not published anywhere).
>
> Ben
------------------------------
Date: Mon, 25 Feb 2008 13:41:29 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to get an account at cpan.org?
Message-Id: <95ta95-vd3.ln1@osiris.mauzo.dyndns.org>
[please don't top-post]
Quoth "Alos Diaf" <alodiaf@yahoo.de>:
> Ben Morrow <ben@morrow.me.uk>:
> > Quoth "Alos Diaf" <alodiaf@yahoo.de>:
> >>
> >> wanna publish a module,
> >> have to register at pause,
> >> want to use a myname@cpan.org, who can i get such?
> >
> > See http://pause.perl.org/pause/query?ACTION=request_id .
> > You need a (non-cpan) email address, but this can be completely private
> > (not published anywhere).
>
> thanx Ben,
> i want a cpan.org address, how to get it?
*Using* *that* *page*. The only way to get an @cpan.org address is to
register with PAUSE, which in turn requires you to already have an
existing email address (which FOO@cpan.org will forward to). That's just
how it works.
Ben
------------------------------
Date: Mon, 25 Feb 2008 05:42:16 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Feb 25 2008
Message-Id: <Jws56G.1D9y@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Algorithm-FastPermute-0.999
http://search.cpan.org/~robin/Algorithm-FastPermute-0.999/
Rapid generation of permutations
----
App-Smarkmail-0.001
http://search.cpan.org/~rjbs/App-Smarkmail-0.001/
pipemailer that changes plaintext to multi/alt with Markdown
----
App-Smarkmail-0.002
http://search.cpan.org/~rjbs/App-Smarkmail-0.002/
pipemailer that changes plaintext to multi/alt with Markdown
----
Array-Each-Override-0.02
http://search.cpan.org/~arc/Array-Each-Override-0.02/
each for iterating over an array's keys and values
----
B-Generate-1.12_06
http://search.cpan.org/~jcromie/B-Generate-1.12_06/
Create your own op trees.
----
Chart-OFC-0.06
http://search.cpan.org/~drolsky/Chart-OFC-0.06/
Generate data files for use with Open Flash Chart
----
Class-AutoGenerate-0.04
http://search.cpan.org/~hanenkamp/Class-AutoGenerate-0.04/
Automatically generate code upon require or use
----
Class-AutoGenerate-0.05
http://search.cpan.org/~hanenkamp/Class-AutoGenerate-0.05/
Automatically generate code upon require or use
----
DBIx-NamedBinding-0.01
http://search.cpan.org/~ydna/DBIx-NamedBinding-0.01/
use named parameters instead of '?'
----
Data-ObjectDriver-0.05
http://search.cpan.org/~btrott/Data-ObjectDriver-0.05/
Simple, transparent data interface, with caching
----
Devel-PerlySense-0.0145
http://search.cpan.org/~johanl/Devel-PerlySense-0.0145/
Perl IDE with Emacs frontend
----
Devel-REPL-1.002000
http://search.cpan.org/~mstrout/Devel-REPL-1.002000/
a modern perl interactive shell
----
Devel-REPL-1.002001
http://search.cpan.org/~mstrout/Devel-REPL-1.002001/
a modern perl interactive shell
----
Egg-Plugin-LWP-3.00
http://search.cpan.org/~lushe/Egg-Plugin-LWP-3.00/
LWP for Egg Plugin.
----
Egg-Plugin-Net-Ping-3.00
http://search.cpan.org/~lushe/Egg-Plugin-Net-Ping-3.00/
Net::Ping for Egg plugin.
----
Egg-Plugin-Net-Scan-3.00
http://search.cpan.org/~lushe/Egg-Plugin-Net-Scan-3.00/
Network host's port is checked.
----
Egg-Release-Authorize-0.01
http://search.cpan.org/~lushe/Egg-Release-Authorize-0.01/
Package kit for attestation.
----
Fey-Loader-0.05
http://search.cpan.org/~drolsky/Fey-Loader-0.05/
Load your schema defintion from a DBMS
----
Fey-ORM-0.03
http://search.cpan.org/~drolsky/Fey-ORM-0.03/
A Fey-based ORM
----
File-PathInfo-1.21
http://search.cpan.org/~leocharre/File-PathInfo-1.21/
access to path variables, stat data, misc info about a file
----
Finance-Bank-Cahoot-0.04
http://search.cpan.org/~masaccio/Finance-Bank-Cahoot-0.04/
Check your Cahoot bank accounts from Perl
----
Games-Go-SGF-0.06
http://search.cpan.org/~deg/Games-Go-SGF-0.06/
Parse and dissect Standard Go Format files
----
Gnome2-VFS-1.081
http://search.cpan.org/~tsch/Gnome2-VFS-1.081/
Perl interface to the 2.x series of the GNOME VFS library
----
Hardware-Simulator-MIX-0.1
http://search.cpan.org/~litchie/Hardware-Simulator-MIX-0.1/
----
IO-Socket-SSL-1.13_3
http://search.cpan.org/~sullr/IO-Socket-SSL-1.13_3/
Nearly transparent SSL encapsulation for IO::Socket::INET.
----
IPC-ShareLite-0.10
http://search.cpan.org/~andya/IPC-ShareLite-0.10/
Lightweight interface to shared memory
----
Iterator-File-Line-0.00002
http://search.cpan.org/~dmaki/Iterator-File-Line-0.00002/
Iterate A File By Line
----
JSON-RPC-0.96
http://search.cpan.org/~makamaka/JSON-RPC-0.96/
Perl implementation of JSON-RPC 1.1 protocol
----
JSON-RPC-Server-FastCGI-0.02
http://search.cpan.org/~faiz/JSON-RPC-Server-FastCGI-0.02/
A FastCGI version of JSON::RPC::Server
----
Math-MatrixReal-2.04
http://search.cpan.org/~leto/Math-MatrixReal-2.04/
Matrix of Reals
----
Metadata-DB-1.09
http://search.cpan.org/~leocharre/Metadata-DB-1.09/
----
Module-Install-AuthorTests-0.001
http://search.cpan.org/~rjbs/Module-Install-AuthorTests-0.001/
designate tests only run by module authors
----
Music-Tag-0.33
http://search.cpan.org/~ealleniii/Music-Tag-0.33/
Interface for collecting information about music files.
----
Music-Tag-Amazon-0.31
http://search.cpan.org/~ealleniii/Music-Tag-Amazon-0.31/
Plugin module for Music::Tag to get information from Amazon.com
----
NET-IPFilterSimple_V1.0
http://search.cpan.org/~senger/NET-IPFilterSimple_V1.0/
Perl extension accessing ipfilter.dat files the very simple way
----
NET-IPFilter_V1.1
http://search.cpan.org/~senger/NET-IPFilter_V1.1/
Perl extension for Accessing eMule / Bittorrent IPFilter.dat Files and checking a given IP against this ipfilter.dat IP Range. IT uses conversion from IP to long integers in Perl and afterwards compai
----
Net-Address-Ethernet-1.110
http://search.cpan.org/~mthurn/Net-Address-Ethernet-1.110/
find hardware ethernet address
----
Net-Flickr-Geo-0.6
http://search.cpan.org/~ascope/Net-Flickr-Geo-0.6/
tools for working with geotagged Flickr photos
----
Net-Flickr-RDF-2.1
http://search.cpan.org/~ascope/Net-Flickr-RDF-2.1/
a.k.a RDF::Describes::Flickr
----
Number-Base-DWIM-0.04
http://search.cpan.org/~cmo/Number-Base-DWIM-0.04/
delay parsing of based constants as long as possible.
----
POD2-Base-0.041
http://search.cpan.org/~ferreira/POD2-Base-0.041/
Base module for translations of Perl documentation
----
POE-Component-Lingua-Translate-0.04
http://search.cpan.org/~hinrik/POE-Component-Lingua-Translate-0.04/
A non-blocking wrapper around Lingua::Translate
----
RPSL-0.26
http://search.cpan.org/~lmc/RPSL-0.26/
Router Policy Specification Language
----
Rubric-Entry-Formatter-Markdown-0.553
http://search.cpan.org/~rjbs/Rubric-Entry-Formatter-Markdown-0.553/
format entries with Markdown (duh!)
----
Test-Presenter-0.3
http://search.cpan.org/~markwkm/Test-Presenter-0.3/
A module for results Presentation.
----
Test-Simple-0.76_01
http://search.cpan.org/~mschwern/Test-Simple-0.76_01/
Basic utilities for writing tests.
----
Test-Simple-0.76_02
http://search.cpan.org/~mschwern/Test-Simple-0.76_02/
Basic utilities for writing tests.
----
Test-Strict-0.09
http://search.cpan.org/~pdenis/Test-Strict-0.09/
Check syntax, presence of use strict; and test coverage
----
WWW-Search-Ebay-2.233
http://search.cpan.org/~mthurn/WWW-Search-Ebay-2.233/
backend for searching www.ebay.com
----
XML-Writer-0.604
http://search.cpan.org/~josephw/XML-Writer-0.604/
Perl extension for writing XML documents.
----
autobox-2.22
http://search.cpan.org/~chocolate/autobox-2.22/
call methods on builtin types
----
autobox-2.23
http://search.cpan.org/~chocolate/autobox-2.23/
call methods on builtin types
----
perlconsole-0.4
http://search.cpan.org/~sukria/perlconsole-0.4/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 25 Feb 2008 16:48:16 +0100
From: Mikael Petterson <mikael.petterson@ericsson.com>
Subject: Problem using find on win32
Message-Id: <fpuo00$j4m$1@news.al.sw.ericsson.se>
Hi,
I am trying to find the following file ( where version number can vary)
org.eclipse.equinox.lanucher_x.x.x.jar in "C:\\Tools\\SDS\\plugins\\"
sub equinox (){
$jar = $File::Find::name if /\Aorg\.eclipse\.equinox\.launcher_.*\.jar\z/;
}
my $equinoxDir = "C:\\Tools\\SDS\\plugins\\
find (\&equinox,$equinoxDir);
I can see that the path for files & directories found using find becomes:
/mydir/file1.txt
/mydir/file2.txt
and so on.
So the full path becomes:
C:\\Tools\\SDS\\plugins\\/mydir
which does not work.
How can make paths be the same.
--
Mikael Petterson
Software Designer
Ericsson AB, Stockholm, Sweden
Visiting address: Isafjordsgatan 15, Kista
Phone: +46 70 2673044
E-mail: mikael.petterson@ericsson.com
------------------------------
Date: Mon, 25 Feb 2008 02:48:37 -0800 (PST)
From: Praki <visitprakashindia@gmail.com>
Subject: Session Expiration Problem
Message-Id: <cc763224-1e11-4c65-9661-ab672d146225@f47g2000hsd.googlegroups.com>
Hi All,
This is the coding i have writtern to create the session in Perl.but i
getting session expired with in 5 min even if i m contineously wroking
onthe page.
$userid = $FORM{'uid'};
$password = $FORM{'password'};
$session = new CGI::Session("driver:File",undef,{'Directory'=>"/
tmp"});
$sid = $session->id();
# Write the session variable on the server
$session->param('username',$userid);
# $session->param('password',$password);
#create session cookie
$cookie = $query->cookie(CGISESSID => $session->id);
#session expire
$session->expire('+24h');
this code checks for the session existence
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
print $query->header( -cookie=>$cookie );
$username_session = $session->param('username');
if ($username_session eq "") {
&print_session_exp_header(" -- Session Expired -- ","Session
Expired.");
print "<h5>Please Relogin in Different Browser</h5>";
&print_trailer();
exit(0);
}
i dont know where i m going wrong.
can anyone plz correct with i have done any mistake or pointer to
correct the mistake.
thaks in advance
prakash
------------------------------
Date: Mon, 25 Feb 2008 05:18:12 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: setting %ENV in a module
Message-Id: <klv995-it9.ln1@osiris.mauzo.dyndns.org>
Quoth pgodfrin <pgodfrin@gmail.com>:
>
> Here are the results:
> package Mymod;
> use strict;
> use warnings;
> our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);
Don't declare variables up-front like this. Perl isn't C or Pascal.
Declare them as you first need them.
> require Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw(setrun);
>
> sub setrun
> {
> my($evf)=@_ ;
Your code will be much easier to follow if you indent properly.
> my($RVARS,$e,$v);
> open $RVARS,"<","$evf" or die "Can't open input: $evf\n";
> foreach (<$RVARS>)
> {
> if (($e,$v) = /^export\s+(\w+)=(.+)/)
If you had used
if (my ($e, $v) = ...) {
as I originally had, $e and $v would be scoped to the 'if' statement. It
is always best to give variables as small a scope as you can.
> {
> for ($v)
> {
> s/(?<!\\)\$(\w+)/$ENV{$1}/g;
> s/\\(.)/$1/g;
To expand these two a little more (note the use of /x, which allows
whitespace and comments in the 'pattern' part):
s/ # replace...
(?<! \\ ) # not immediately after a backslash
# (this prevents '\$foo' from being replaced)
\$ # a dollar sign
(\w+) # an identifier, which will be captured into $1
/$ENV{$1}/gx; # ...with the appropriate env var
s/ # replace...
\\ # a backslash, followed by
(.) # any character (captured into $1)
/$1/gx; # ...with that character (so \\->\, \$->$, etc.)
> }
> $ENV{$e}=$v;
> }
> } # end foreach
Decent indentation makes comments like this redundant.
> close $RVARS;
Since you don't check the return value of close (not usually useful on
filehandles opened for reading, anyway), there's no point in explicitly
calling it. Just let the variable go out of scope, and Perl will close
it for you.
> return 1;
There's no need for a return value like this that doesn't convey any
information to the caller. Falling off the end of a sub is a perfectly
respectable way to return (the return value will in fact be the value of
the last statement executed, but since you don't check it anyway that
doesn't matter). If you do want a 'null' return, a simple
return;
will return undef in scalar context and the empty list in list context,
which is usually appropriate.
> } # end setenv
> 1;
>
> #!/usr/bin/perl
> use warnings;
> no warnings 'once';
> use Env;
I would recommend against using Env, unless you're a shell programmer
trying hard not to really learn Perl (which is OK, of course, but don't
expect a lot of sympathy from the people here :) ). Importing an
unspecified list of variables into your namespace just for the sake of
avoiding a hash lookup is not a good tradeoff. (Shell should be avoided
for much the same reason, neat though the idea is.) The fact that you
have to turn off 'once' warnings should alert you to the fact this is
not necessarily a good idea, though there are of course occasions where
turning off warnings is the right answer.
> #Env::import;
> #use MymodSimp2 ;
> use Mymod;
You will find it makes your life easier later if you use explicit import
lists where practical. When you come to this code later, it makes it
much simpler to work out where setrun is defined if you can see it in
the 'use' line.
use Mymod qw/setrun/;
Also, I presume this is just an example, but you should *really* choose
a better name than 'Mymod'. I tend to use BMORROW::* for my own private
modules, so I'd call this something like BMORROW::SetEnv, which means it
would need to live in a file called SetEnv.pm in a directory BMORROW
somewhere in @INC.
> setrun("etfile");
> print "TMPTEST: $ENV{TMPTEST}\n";
If you set $\ (or use the -l switch on the #! line) Perl will add those
newlines for you. If you have 5.10 you can use 'say' instead of 'print'
for the same effect. Also, several lines of print statements usually
work better as a heredoc:
print <<ENV;
TMPTEST: $ENV{TMPTEST}
TMPTOO: $ENV{TMPTOO}
Now with scalar vars...
TMPTEST: $TMPTEST
ENV
See how much easier it is to get things lined up when you can see how
they will appear?
> print "TMPTOO: $ENV{TMPTOO}\n";
> print "Now with scalar vars...\n";
> Env::import;
You do realise Env->import (which is subtly but importantly different
from Env::import) has already been called, at compile time, by the 'use'
statement? If it hadn't, the next two lines would never have got past
'use strict'.
> print "TMPTEST: $TMPTEST\n";
> print "TMPTOO: $TMPTOO\n";
> exit;
Again, there's no need to explicitly exit unless you want to do so
early. Falling off the end of the program is a perfectly good way out.
Ben
------------------------------
Date: Mon, 25 Feb 2008 07:43:22 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: setting %ENV in a module
Message-Id: <0644e711-5357-45cc-9f1d-73005424ca58@e60g2000hsh.googlegroups.com>
On Feb 24, 11:18 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth pgodfrin <pgodf...@gmail.com>:
>
>
>
> > Here are the results:
> > package Mymod;
> > use strict;
> > use warnings;
> > our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);
>
> Don't declare variables up-front like this. Perl isn't C or Pascal.
> Declare them as you first need them.
>
> > require Exporter;
> > @ISA = qw(Exporter);
> > @EXPORT = qw(setrun);
>
> > sub setrun
> > {
> > my($evf)=@_ ;
>
> Your code will be much easier to follow if you indent properly.
>
> > my($RVARS,$e,$v);
> > open $RVARS,"<","$evf" or die "Can't open input: $evf\n";
> > foreach (<$RVARS>)
> > {
> > if (($e,$v) = /^export\s+(\w+)=(.+)/)
>
> If you had used
>
> if (my ($e, $v) = ...) {
>
> as I originally had, $e and $v would be scoped to the 'if' statement. It
> is always best to give variables as small a scope as you can.
>
> > {
> > for ($v)
> > {
> > s/(?<!\\)\$(\w+)/$ENV{$1}/g;
> > s/\\(.)/$1/g;
>
> To expand these two a little more (note the use of /x, which allows
> whitespace and comments in the 'pattern' part):
>
> s/ # replace...
>
> (?<! \\ ) # not immediately after a backslash
> # (this prevents '\$foo' from being replaced)
>
> \$ # a dollar sign
>
> (\w+) # an identifier, which will be captured into $1
>
> /$ENV{$1}/gx; # ...with the appropriate env var
>
> s/ # replace...
> \\ # a backslash, followed by
> (.) # any character (captured into $1)
> /$1/gx; # ...with that character (so \\->\, \$->$, etc.)
>
> > }
> > $ENV{$e}=$v;
> > }
> > } # end foreach
>
> Decent indentation makes comments like this redundant.
>
> > close $RVARS;
>
> Since you don't check the return value of close (not usually useful on
> filehandles opened for reading, anyway), there's no point in explicitly
> calling it. Just let the variable go out of scope, and Perl will close
> it for you.
>
> > return 1;
>
> There's no need for a return value like this that doesn't convey any
> information to the caller. Falling off the end of a sub is a perfectly
> respectable way to return (the return value will in fact be the value of
> the last statement executed, but since you don't check it anyway that
> doesn't matter). If you do want a 'null' return, a simple
>
> return;
>
> will return undef in scalar context and the empty list in list context,
> which is usually appropriate.
>
> > } # end setenv
> > 1;
>
> > #!/usr/bin/perl
> > use warnings;
> > no warnings 'once';
> > use Env;
>
> I would recommend against using Env, unless you're a shell programmer
> trying hard not to really learn Perl (which is OK, of course, but don't
> expect a lot of sympathy from the people here :) ). Importing an
> unspecified list of variables into your namespace just for the sake of
> avoiding a hash lookup is not a good tradeoff. (Shell should be avoided
> for much the same reason, neat though the idea is.) The fact that you
> have to turn off 'once' warnings should alert you to the fact this is
> not necessarily a good idea, though there are of course occasions where
> turning off warnings is the right answer.
>
> > #Env::import;
> > #use MymodSimp2 ;
> > use Mymod;
>
> You will find it makes your life easier later if you use explicit import
> lists where practical. When you come to this code later, it makes it
> much simpler to work out where setrun is defined if you can see it in
> the 'use' line.
>
> use Mymod qw/setrun/;
>
> Also, I presume this is just an example, but you should *really* choose
> a better name than 'Mymod'. I tend to use BMORROW::* for my own private
> modules, so I'd call this something like BMORROW::SetEnv, which means it
> would need to live in a file called SetEnv.pm in a directory BMORROW
> somewhere in @INC.
>
> > setrun("etfile");
> > print "TMPTEST: $ENV{TMPTEST}\n";
>
> If you set $\ (or use the -l switch on the #! line) Perl will add those
> newlines for you. If you have 5.10 you can use 'say' instead of 'print'
> for the same effect. Also, several lines of print statements usually
> work better as a heredoc:
>
> print <<ENV;
> TMPTEST: $ENV{TMPTEST}
> TMPTOO: $ENV{TMPTOO}
> Now with scalar vars...
> TMPTEST: $TMPTEST
> ENV
>
> See how much easier it is to get things lined up when you can see how
> they will appear?
>
> > print "TMPTOO: $ENV{TMPTOO}\n";
> > print "Now with scalar vars...\n";
> > Env::import;
>
> You do realise Env->import (which is subtly but importantly different
> from Env::import) has already been called, at compile time, by the 'use'
> statement? If it hadn't, the next two lines would never have got past
> 'use strict'.
>
> > print "TMPTEST: $TMPTEST\n";
> > print "TMPTOO: $TMPTOO\n";
> > exit;
>
> Again, there's no need to explicitly exit unless you want to do so
> early. Falling off the end of the program is a perfectly good way out.
>
> Ben
Hi Ben,
Thanks for the advice. Yes this is only example or testing code. And
thanks for explaining the RE - that helps a lot. I wasn't aware that
it was OK to permit file handles to close by going out of scope, nor
that it was ok to leave a routine without a return. I'll follow up on
that a little more, because I really do want to learn Perl better. I'm
neither a perl programmer, nor a shell script-er, but a DBA (since,
like, before there were relational databases!).
So essentially all I want to do is the DBA stuff, using perl instead
of shell, which is why you see me asking questions about environment
variables and executing processes in the background :).
In any case, the reason I predeclared the $VERSION and the @...
subroutines is because I saw that in an example in some discussion of
making perl modules. Could you suggest a definitive doc for creating
modules?
About the use Env and Env::import - my goal for these perl scripts
(programs?) was to make them executable from either the command line,
cron or some other scheduling package. So, I am indeed trying to avoid
a hash lookup, mostly for cosmetic's sake, but also for other DBA's
who have never seen perl and refuse to be brought into the [perl]
fold. It would be easier for them to see $mydir="$HOME" as opposed to
$mydir=$ENV{HOME}. However, I am in the habit of calling Env qw(HOME);
so as to minimize what I'm using.
But to be honest I really don't fully understand module coding and
"EXPORTing" and what the difference is between use Mymod and use Mymod
qw(setrun) really is. which is why I asked about a definitive doc for
that...
But all in all - thanks very, very much for your help and advice - and
anyway who needs your sympathy! <grin>
regards,
pg
------------------------------
Date: Mon, 25 Feb 2008 08:03:09 -0800 (PST)
From: Petyr David <phynkel@gmail.com>
Subject: Re: Speeding my script
Message-Id: <2ab20c99-0c91-4264-93b2-a60783ae6140@p25g2000hsf.googlegroups.com>
On Feb 23, 3:07 am, nos...@geniegate.com (Jamie) wrote:
> In <29fba8f0-26f0-4b2e-9dbd-637445719...@n77g2000hse.googlegroups.com>,
> Petyr David <phyn...@gmail.com> mentions:
>
> >have a web page calling PERL script that searches for patterns in 20,
> >000 files + and returns link to files and lines found matching
> >pattern. I use a call to `find` and `egrep`
>
> That is going to take a long, long time.
>
> >Q: Script works - but is straining under the load - files are in the
> >Gbs.
> > How to speed process? How simple to employ threads or slitting
> >off
> > new processes?
>
> Thats an option. Check into File::Find, fork() and pipes. You could
> create some pipes, fork several processes, do a select on the handles
> and run the commands in parallel.
>
> This will still run awfully slow though.
>
> >what I'd like to do is to be able to simultaneously be searching more
> >than 1 subdirectory
>
> If you don't need full regex capability, you could check into indices. If you
> know one of the words, you can use that to filter out which documents to scan.
>
> If you can get the words sorted, look into Search::Dict (or, use a tied hash)
>
> Best bet is to use an index though. Even if it's crude, a substantial amount
> of your time is probably spent opening and closing files. (well, find/grep anyway)
>
> An example of a "crude index" is the whatis database.
>
> When you type 'apropos keyword' you're not opening a zillion manpages and
> scanning them.
>
> Jamie
> --http://www.geniegate.com Custom web programming
> Perl * Java * UNIX User Management Solutions
> If you don't need full regex capability, you could check into indices. If you
> know one of the words, you can use that to filter out which documents to scan.
but I do. I've considered, and will install Swish-e. Would i not be
able to use regexes with something like Swishe-e?
------------------------------
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 1304
***************************************