[28896] in Perl-Users-Digest
Perl-Users Digest, Issue: 140 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 15 14:10:22 2007
Date: Thu, 15 Feb 2007 11:09:08 -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 Thu, 15 Feb 2007 Volume: 11 Number: 140
Today's topics:
Automated testing of cgi / perl spam@comjet.com
Re: Geting Windows NT services and drives. <thepoet_nospam@arcor.de>
Re: manually expire an element in Memoize <greg.ferguson@icrossing.com>
Re: pattern serach over many files <wahab-mail@gmx.de>
Re: pattern serach over many files <rvtol+news@isolution.nl>
perl ftp problems <robt@publicans.com>
Re: Perl interaction with Expect <ecarlson@vmware.com>
Re: Perl interaction with Expect <ecarlson@vmware.com>
re: problem CGI read request POST <john.swilting@wanadoo.fr>
re: problem CGI read request POST <john.swilting@wanadoo.fr>
Re: problem CGI <rvtol+news@isolution.nl>
Re: problem CGI <john.swilting@wanadoo.fr>
Re: script for http request <greg.ferguson@icrossing.com>
Re: script for http request <no@email.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Feb 2007 10:51:31 -0800
From: spam@comjet.com
Subject: Automated testing of cgi / perl
Message-Id: <1171565491.430048.105110@j27g2000cwj.googlegroups.com>
Hello, I have the following situation:
- Existing site with about 18,000 cgi pages.
- Most pages are data driven (fill out form, submit, get results).
Exact results may change from day to day as data get updated.
- Some static html mixed in
- Many pages require authentication. It is a custom in-house
authentication mechanism, but ultimately it stores a temporary session
ID in a session cookie.
I would like to implement automated testing that will:
- Tell me if anything breaks.
- Tell me if a new installation of the same overall site is working
the same as the original (for an upgrade project).
- Tell me if I break anything during maintenance (regression testing)
Can anyone give me some pointers on this? Tool? Overall approach?
Pitfalls? Any clues appreciated.
Larry
------------------------------
Date: Thu, 15 Feb 2007 19:32:33 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Geting Windows NT services and drives.
Message-Id: <45d4a73a$0$15943$9b4e6d93@newsspool4.arcor-online.net>
490 wrote:
> I am trying to get win NT services and drives detailes.
> I used the code:
>
> 'WINMSD /f' ;
> 'set >info.txt';
>
> And then i go through the details and get what i want form the txt
> file.
> The problem is that this is a very ugly way and it uses alot of CPU &
> Memory Usage.
>
> Does any body have a better and faster way?!
I'd use Win32::OLE and the WMI for that. The WMI classes are
well documented over at msdn.microsoft.com (there you will find
all attributes explained, like e.g. the DriveType numbers I'm
using in the example), and using them is quite straight forward.
Though if I recall correctly, WMI has to be installed manually
on NT 4 (requiring SP4 or above), but this has the bonus of
running on later MS-OSes without changes, whereas the "write
text" option of winmsd got lost somewhere along the way.
----------------------------------------------------------------
#!/perl
use strict;
use warnings;
use Win32::OLE qw(in);
my $computer = "."; # MS's short notation for "this host"
my $wmi = Win32::OLE->GetObject(
'winmgmts:{impersonationLevel=impersonate,(security)}//' .
$computer .
'/root/CIMV2'
);
print "Logical Drives:" . $/;
print "===============" . $/;
my $drives = $wmi->ExecQuery(
'SELECT * FROM Win32_LogicalDisk ' .
'WHERE DriveType = 2 OR DriveType = 3'
);
foreach my $drive ( in($drives) )
{
printf( "%s %-12s Bytes, %-12s Bytes free$/",
$drive->{'Name'},
$drive->{'Size'},
$drive->{'FreeSpace'}
);
}
print "Services:" . $/;
print "=========" . $/;
my $services = $wmi->ExecQuery('SELECT * FROM Win32_Service');
foreach my $srvc ( in($services) )
{
printf("%-30s %10s: %-10s (%s)$/",
$srvc->{'Name'},
"[" . $srvc->{'StartMode'} . "]",
$srvc->{'State'},
$srvc->{'PathName'}
);
}
----------------------------------------------------------------
HTH
-Chris
------------------------------
Date: 15 Feb 2007 08:20:57 -0800
From: "gf" <greg.ferguson@icrossing.com>
Subject: Re: manually expire an element in Memoize
Message-Id: <1171556457.090242.76790@v33g2000cwv.googlegroups.com>
On Feb 14, 3:41 pm, danielmcbrea...@gmail.com wrote:
> hi all
>
> I like and use MJ Dominus' excellent Memoize module to cache some
> stuff in my app that hits a db rather hard. It's very simple :
>
> use Memoize;
>
> memoize('my_accessor');
>
> sub my_accessor {
> my ($key1, $key2) = @_;
> # look up $key1, $key2 in the db and return a scalar
>
> }
>
> and the function is magically cached without the need to do any more.
>
> Now what I'd like is, in another function, to manually invalidate (or
> delete) certain cached values at runtime (most likely because I
> changed the value in the db).
>
> How can I do this? I looked at the docs and source for
> Memoize::Expire, but it's not too clear to me right now. Obviously,
> I'd like the simplest possible solution ...
Memoize is cool, but if you need more flexibility or other features
then rolling a simple version isn't hard.
Wrap your function in an extra set of braces kinda like this ...
{
my %memo_cache;
sub blah {
return $memo_cache{@_} if $memo_cache{@_};
...
my $return_value =
do_some_calculating_to_create_a_return_value...
...
$memo_cache{@_} = $return_value;
return $return_value;
}
}
If you need to be able expire an element in your cache then you add an
additional sub inside the outer braces...
{
my %memo_cache;
sub drop_cache_value {
delete $memo_cache{@_};
}
sub blah {
return $memo_cache{@_} if $memo_cache{@_};
...
my $return_value =
do_some_calculating_to_create_a_return_value...
...
$memo_cache{@_} = $return_value;
return $return_value;
}
}
And call the drop_cache_value() with the same values used to initially
create the memoized entry when you determine that that element in the
hash needs to be deleted.
The downside of doing it yourself is you might not handle conditions
that Memoize or a similar module already handles.
------------------------------
Date: Thu, 15 Feb 2007 17:07:19 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: pattern serach over many files
Message-Id: <er20pq$nr$1@mlucom4.urz.uni-halle.de>
Mirco Wahab wrote:
> Change one line
> ...
> in order to find lines w/all three occurrences
BTW, my initial code was more like 'enhanced pseudo Perl',
so if you are interested to do some more Perl, you should
adopt to a more robust programming style, you should
for example (at least) check opened file handles and
avoid unnecessary repeated statements, more like:
[revamped example]
use strict;
use warnings;
my $term = qr/abc/;
my @name = qw' file1.txt file2.txt file3.txt ';
open my $f1, '<', $name[0] or warn "$name[0] $!";
open my $f2, '<', $name[1] or warn "$name[1] $!";;
open my $f3, '<', $name[2] or warn "$name[2] $!";;
my ($count, $line) = (0, 0);
while( ! eof($f1) and ! eof($f2) and ! eof($f3) ) {
my @lines = (scalar <$f1>, scalar <$f2>, scalar <$f3>);
++$line;
print ++$count, ". # $line\n" if 3 == grep /$term/, @lines;
}
print "Total: $count\n";
...
Regards
M.
------------------------------
Date: Thu, 15 Feb 2007 18:33:37 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: pattern serach over many files
Message-Id: <er292p.1g8.1@news.isolution.nl>
pavan734@gmail.com schreef:
> I think you have misunderstood.
No, you have misunderstood. An approach was shown, for you to learn.
Tip: With larger files, a while loop takes less memory.
Also: You really shouldn't quote old text that is not relevant to your
reply. Especially don't quote signatures!
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 15 Feb 2007 09:38:08 -0800
From: "robt" <robt@publicans.com>
Subject: perl ftp problems
Message-Id: <1171561088.852556.270170@s48g2000cws.googlegroups.com>
I have a perl script using the ftp module which I'm having a problem
with. The script ftp's a file to a server and will first rename the
file on the server if it already exists. I am receiving errors from
the script if I am connecting to a Solaris 9 or 10 server but it works
fine if I connect to a Solaris 8 server. The code I'm having trouble
with is:
@files=$ftp->ls("$filename") or $err=1;
When connecting to a solaris 8 server, the filename is returned if the
file exists and the following is returned if it does not exist:
/bin/ls: tst1: No such file or directory
However, when connecting to a solaris 10 server, the filename is
returned if the file exists but I receive the following error if the
file does not exist:
Illegal seek
Has anyone run into this problem and is there a solution?
Thanks.
------------------------------
Date: 15 Feb 2007 09:00:20 -0800
From: "Eric" <ecarlson@vmware.com>
Subject: Re: Perl interaction with Expect
Message-Id: <1171558818.013027.288780@l53g2000cwa.googlegroups.com>
On Feb 14, 11:56 pm, "Mumia W." <paduille.4060.mumia.w
+nos...@earthlink.net> wrote:
> On 02/14/2007 02:54 PM, Eric wrote:
>
>
>
>
>
> > Hello,
>
> > I'm not sure if this is a Perl question or an Expect question. But I
> > will start here.
>
> > I have written an Expect script that someone else is executing in
> > their Perl script. I would like my Expect script to return a string as
> > a value to this Perl script, not a boolean (i.e. integer).
>
> > For example, say my Expect script does something like this:
>
> > if (<this>) {
> > return "SUCCESS";
> > } else {
> > return "FAILURE";
> > }
>
> > The Perl script needs to have the value returned as either a "SUCCESS"
> > or "FAILURE".
>
> > I created a short Perl script that executes the Expect script by doing
> > the following:
>
> > my $rtnval = `rem.exp`;
>
> > Of course, that's not going to return the value I am looking for; it's
> > only going to print the output to stdout. And if I try:
>
> > my $rtnval = system("rem.exp");
>
> > that's only going to tell me if the system call passed or failed (i.e.
> > an integer), regardless of whether the Expect script deemed a success
> > or fail.
>
> > How can I call an Expect script from a Perl script and return a string
> > value? Is there some trick to getting an interaction between Perl and
> > Expect? I suppose I could do some kludge, like read the output into a
> > file and search the file for the response. But I'd rather avoid that
> > if possible.
>
> > Thanks in advance to all that respond.
>
> > Eric
>
> AFAIK, you cannot get a string return value from a separate process. You
> will either have to rewrite the Expect script to send the "SUCCESS" or
> "FAILURE" to STDOUT, or you'll have to use the kludge you mentioned.
>
> --
> Windows Vista and your freedom in conflict:http://techdirt.com/articles/20061019/102225.shtml- Hide quoted text -
>
> - Show quoted text -
Thanks for your response. If I do print the response to STDOUT (using
send_user or puts), the Perl script that's calling the Expect script
will have to be able read this output somehow (TBD). Is that correct?
Eric
------------------------------
Date: 15 Feb 2007 10:10:34 -0800
From: "Eric" <ecarlson@vmware.com>
Subject: Re: Perl interaction with Expect
Message-Id: <1171563034.775413.214960@m58g2000cwm.googlegroups.com>
On Feb 15, 9:00 am, "Eric" <ecarl...@vmware.com> wrote:
> On Feb 14, 11:56 pm, "Mumia W." <paduille.4060.mumia.w
>
>
>
>
>
> +nos...@earthlink.net> wrote:
> > On 02/14/2007 02:54 PM, Eric wrote:
>
> > > Hello,
>
> > > I'm not sure if this is a Perl question or an Expect question. But I
> > > will start here.
>
> > > I have written an Expect script that someone else is executing in
> > > their Perl script. I would like my Expect script to return a string as
> > > a value to this Perl script, not a boolean (i.e. integer).
>
> > > For example, say my Expect script does something like this:
>
> > > if (<this>) {
> > > return "SUCCESS";
> > > } else {
> > > return "FAILURE";
> > > }
>
> > > The Perl script needs to have the value returned as either a "SUCCESS"
> > > or "FAILURE".
>
> > > I created a short Perl script that executes the Expect script by doing
> > > the following:
>
> > > my $rtnval = `rem.exp`;
>
> > > Of course, that's not going to return the value I am looking for; it's
> > > only going to print the output to stdout. And if I try:
>
> > > my $rtnval = system("rem.exp");
>
> > > that's only going to tell me if the system call passed or failed (i.e.
> > > an integer), regardless of whether the Expect script deemed a success
> > > or fail.
>
> > > How can I call an Expect script from a Perl script and return a string
> > > value? Is there some trick to getting an interaction between Perl and
> > > Expect? I suppose I could do some kludge, like read the output into a
> > > file and search the file for the response. But I'd rather avoid that
> > > if possible.
>
> > > Thanks in advance to all that respond.
>
> > > Eric
>
> > AFAIK, you cannot get a string return value from a separate process. You
> > will either have to rewrite the Expect script to send the "SUCCESS" or
> > "FAILURE" to STDOUT, or you'll have to use the kludge you mentioned.
>
> > --
> > Windows Vista and your freedom in conflict:http://techdirt.com/articles/20061019/102225.shtml-Hide quoted text -
>
> > - Show quoted text -
>
> Thanks for your response. If I do print the response to STDOUT (using
> send_user or puts), the Perl script that's calling the Expect script
> will have to be able read this output somehow (TBD). Is that correct?
>
> Eric- Hide quoted text -
>
> - Show quoted text -
Thanks to everyone that responded. I was able to get something to
work
by using bacticks to capture the response of the Expect program and
then parsing it using Perl.
This was a much easier problem than I was making it. I guess I got
caught up in the mindset of Perl-Expect interaction.
Eric
------------------------------
Date: Thu, 15 Feb 2007 17:25:22 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: re: problem CGI read request POST
Message-Id: <45d48965$0$25935$ba4acef3@news.orange.fr>
john.swilting wrote:
> how to read a whole a requete post to extract the arguments there
On Wed, 14 Feb 2007 15:22:39 +0100, "john.swilting"
<john.swilting@wanadoo.fr> wrote:
>> I am afraid to find me with much
>> my $1 = $cgi->param('1');
>that will be a gas works
I beg your pardon?!?
Michele
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 15 Feb 2007 17:39:18 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: re: problem CGI read request POST
Message-Id: <45d48caa$0$25910$ba4acef3@news.orange.fr>
john.swilting wrote:
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$FORM{$name} = $value;
}
------------------------------
Date: Thu, 15 Feb 2007 18:38:49 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: problem CGI
Message-Id: <er29c8.1g8.1@news.isolution.nl>
john.swilting schreef:
> #!/usr/bin/perl -w
> use strict;
Make that:
#!/usr/bin/perl
use strict;
use warnings;
(unless you run a very old perl)
Or Abigail-style:
#!/usr/bin/perl
use warnings;
use strict;
no warnings 'syntax';
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 15 Feb 2007 19:19:19 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: Re: problem CGI
Message-Id: <45d4a422$0$25932$ba4acef3@news.orange.fr>
Dr.Ruud wrote:
> unless you run a very old perl
why
I did new to a post anybody does not answer me
------------------------------
Date: 15 Feb 2007 09:47:32 -0800
From: "gf" <greg.ferguson@icrossing.com>
Subject: Re: script for http request
Message-Id: <1171561652.531009.304280@k78g2000cwa.googlegroups.com>
On Feb 15, 8:39 am, "RogerF" <rfren...@gmail.com> wrote:
> Hello... don't do alot of perl scripting so I am not well experienced
> with scripting...
>
> I want to return the values from a simple http request in a perl
> script.
>
> So for example, if I have a http request on a server such as:
>
> http://<server>/servlet/inbasket?RDUSER=pfuser&FUNCTION=gettasks
>
> And the return of the URL is:
>
> <?xml version="1.0" ?>
> - <INBASKET>
> <USERTASKS userid="" returnmsg="No tasks set up for workflow user
> pfuser" msgtype="Error" />
> </INBASKET>
>
> I want to take the returnmsg value ("No tasks set up for workflow user
> pfuser") from the request and send it to an email recipient.
>
> Just looking for the syntax of the Http request and how to get the
> return values
>
> require HTTP::Request;
> $request = HTTP::Request->new(GET => 'http://<server>/servlet/inbasket?
> RDUSER=pfuser&FUNCTION=gettasks');
> ...
> ...
> ...
> $response = $ua->request($request)
> if ($response->is_success) {
> print $response->content;
> }
> else {
> print STDERR $response->status_line, "\n";
> ********************************************************************
Just addressing your HTTP request...
If all you are doing is making a simple request and not needing a lot
of control over how LWP behaves, then use LWP::Simple.
Then your request becomes a simple get('url') call, which returns
whatever the server sent.
------------------------------
Date: Thu, 15 Feb 2007 17:56:25 +0000
From: Brian Wakem <no@email.com>
Subject: Re: script for http request
Message-Id: <53jl6aF1svo94U1@mid.individual.net>
gf wrote:
> Just addressing your HTTP request...
>
> If all you are doing is making a simple request and not needing a lot
> of control over how LWP behaves, then use LWP::Simple.
>
> Then your request becomes a simple get('url') call, which returns
> whatever the server sent.
Minus the headers.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
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 140
**************************************