[28904] in Perl-Users-Digest
Perl-Users Digest, Issue: 148 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 18 00:11:47 2007
Date: Sat, 17 Feb 2007 21:09:03 -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 Sat, 17 Feb 2007 Volume: 11 Number: 148
Today's topics:
Re: Automated testing of cgi / perl spam@comjet.com
Re: convert string of keys to multidimensional hash <nobull67@gmail.com>
Re: convert string of keys to multidimensional hash <wahab-mail@gmx.de>
Re: pattern serach over many files <wahab-mail@gmx.de>
Re: pattern serach over many files <glennj@ncf.ca>
Re: Perl:CGI - Creating a Please wait message <krotowitz@yahoo.com>
Re: Perl:CGI - Creating a Please wait message <krotowitz@yahoo.com>
Re: Regex: Why is overreaching necessary? <Shannon.Jacobs.nospam@gmail.com>
Re: Regexp for email addresses. <stoupa@practisoft.cz>
Re: Regexp for email addresses. <spamtrap@dot-app.org>
Re: Regexp for email addresses. <stoupa@practisoft.cz>
Re: Request for a PERL script to download files <mikeflan@earthlink.net>
Re: Request for a PERL script to download files <tadmc@augustmail.com>
Re: test - disregard <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Feb 2007 06:46:02 -0800
From: spam@comjet.com
Subject: Re: Automated testing of cgi / perl
Message-Id: <1171723562.507239.314440@v33g2000cwv.googlegroups.com>
> I came across Selenium today, which looks rather useful, and has the
> advantage of being able to run tests under various browsers. Also worthy
> of note is jsunit.
>
>
>
> > With so many pages, there must be an automated test plan. Otherwise,
> > how did the site get so large without detecting and fixing bugs? Or was
> > that what your customers are for?
>
> > You can write perl code that uses HTML CPAN libraries to access pages,
> > pretending to be a client. Said connection can input information into
> > fields, even store cookies for session ID between pages.
>
> As an addendum to this:
>
> Test::WWW::Mechanize
>
> would be my first port of call.
>
>
>
> > If you don't already have an automated testing environment for your web
> > application, it's rather late to start developing one.
>
> He's probably inherited a large and rather crufty application and wants
> to make sure nothing breaks as he tries to knock it into shape. Best of
> luck :)
Thanks for the tips! I had seen a couple of these tools around, but
wasn't sure where to start. And yes, you're right, I didn't create
18,000 pages without a test plan. That was someone else.
Larry
------------------------------
Date: 17 Feb 2007 00:20:38 -0800
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: convert string of keys to multidimensional hash
Message-Id: <1171700438.029222.126700@h3g2000cwc.googlegroups.com>
On 17 Feb, 08:08, Mark Clements <mark.clementsREMOVET...@wanadoo.fr>
wrote:
> dt wrote:
> > how do I do this:
>
> > convert a string such as "dim1:dim2:dim3"
> > or array ("dim1", "dim2", "dim3")
>
> > to a hash like:
> > $hash{"dim1"}{"dim2"}{"dim3"}
> my %hash = ();
>
> my $lastItem = \%hash;
>
> foreach my $item(@items){
> my $newItem = {};
> $lastItem->{$item} = $newItem;
> $lastItem = $newItem;
>
> }
This is a very common problem and there's a very simple way to do it
avoiding the last empty hash:
my $lastItem = \\%hash;
$lastItem = \$$lastItem->{$_} for @items;
------------------------------
Date: Sun, 18 Feb 2007 01:05:38 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: convert string of keys to multidimensional hash
Message-Id: <er85j0$rsa$1@mlucom4.urz.uni-halle.de>
dt wrote:
> how do I do this:
>
> convert a string such as "dim1:dim2:dim3"
> or array ("dim1", "dim2", "dim3")
>
> to a hash like:
> $hash{"dim1"}{"dim2"}{"dim3"}
>
> any help is appreciated
after reading Brians excellent reply
(which was somehow new for me), I'd
like to add 2 "functional forms" to
the discussion (recursive), one
ends up with 'undef' on the chain,
the other with a clean hash ref:
...
# end up w/hash ref:
sub rh2arr { rh2arr($_[0]->{$_[1]}={}, @_[2..@_-1]) if @_>1 }
#end up w/undef
sub rrh2arr { rrh2arr(\${$_[0]}->{$_[1]}, @_[2..@_-1]) if @_>1 }
# usage
my @arr = qw'dim1 dim2 dim3';
my (%hash1, %hash2);
rh2arr \%hash1, @arr;
print Dumper \%hash1;
rrh2arr \\%hash2, @arr; # learned \\this from Brian's post ;-)
print Dumper \%hash2;
...
Regards (and thanks to Brian)
Mirco
------------------------------
Date: Sat, 17 Feb 2007 16:19:35 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: pattern serach over many files
Message-Id: <er76ol$ips$1@mlucom4.urz.uni-halle.de>
anno4000@radom.zrz.tu-berlin.de wrote:
>
> my @name = map "file$_.txt", 1 .. 3;
> my @fh;
> open $fh[ @fh], '<', $_ for @name;
>
> while ( ! grep eof( $_), @fh ) {
> chomp( my @lines = map scalar <$_>, @fh);
> # etc...
> }
> # etc...
Not a bad idea!
But much too verbose ... ;-)
use strict;
use warnings;
my (@fh, $count);
open $fh[ @fh ], '<', 'file'.$_.'.txt' for 1..3;
++$count unless grep /abc/, map scalar <$_>, @fh
while( ! grep eof($_), @fh )
print $count if defined $count;
(actually I didn't believe yours would work
at all, but learned from you that
...
map <$_>, @handle_array;
...
does indeed work!
Thanks for that hint.
Regards
Mirco
------------------------------
Date: 17 Feb 2007 20:44:45 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: pattern serach over many files
Message-Id: <slrneteq9u.cf3.glennj@smeagol.ncf.ca>
At 2007-02-17 10:19AM, "Mirco Wahab" wrote:
> anno4000@radom.zrz.tu-berlin.de wrote:
> >
> > my @name = map "file$_.txt", 1 .. 3;
> > my @fh;
> > open $fh[ @fh], '<', $_ for @name;
> >
> > while ( ! grep eof( $_), @fh ) {
> > chomp( my @lines = map scalar <$_>, @fh);
> > # etc...
> > }
> > # etc...
>
> Not a bad idea!
> But much too verbose ... ;-)
>
>
> use strict;
> use warnings;
>
> my (@fh, $count);
> open $fh[ @fh ], '<', 'file'.$_.'.txt' for 1..3;
>
> ++$count unless grep /abc/, map scalar <$_>, @fh
> while( ! grep eof($_), @fh )
>
> print $count if defined $count;
<added value='none'> That's less verbose? </added>
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Sat, 17 Feb 2007 19:18:00 +0100
From: "Marco Neumann" <krotowitz@yahoo.com>
Subject: Re: Perl:CGI - Creating a Please wait message
Message-Id: <er7gdj$gmp$1@news.uni-kl.de>
Hi, Bill!
> Is there anything I can do here or is my only option
> to learn javascripting?
Javascripting won't help you. Try forking like this in your CGI script:
my $pid;
if (!defined ($pid = fork)) {
# This is executed when the forking did not work
# Output an error message.
}
elsif (! $pid) {
# this is the branch for the child process
close(STDIN);
close(STDOUT);
close(STDERR);
# Do long running stuff here
# Then replace the temporary result file
}
# this is the branch for the parent process
# Output a temporary result file (index.html)
# with "please wait blabla" here.
# Then
print "Location: $temporary_response_file\n\n";
exit;
I hope it works for you.
Marco.
------------------------------
Date: Sat, 17 Feb 2007 19:21:15 +0100
From: "Marco Neumann" <krotowitz@yahoo.com>
Subject: Re: Perl:CGI - Creating a Please wait message
Message-Id: <er7gjm$grm$1@news.uni-kl.de>
> I hope it works for you.
Ups just noticed: Insert this into the head of your temporary output file:
<head>
<meta HTTP-EQUIV="refresh" CONTENT="30">
<meta http-equiv="Pragma" content="no-cache">
</head>
This will make it reload every 30 seconds until the child process outputs
the final result file.
Cheers,
Marco.
------------------------------
Date: 17 Feb 2007 18:32:58 -0800
From: "Shannon Jacobs" <Shannon.Jacobs.nospam@gmail.com>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <1171765978.545071.173810@h3g2000cwc.googlegroups.com>
On Feb 17, 10:58 am, anno4...@radom.zrz.tu-berlin.de wrote:
> Shannon Jacobs <sha...@cashette.com> wrote in comp.lang.perl.misc:
>
> [...]
>
> > @foo2 = grep substr( $_, 50, 12 ) =~ /$form_values{'a_SEARCH_VALUE'}/,
> > @foo1;
>
> [...]
>
>
>
> > There's still one more little wrinkle that's bugging me--but there always
> > is. Trivial enough to ignore, but I'm wondering if there's an elegant
> > solution... I'll try to restate that wrinkled problem in terms that are more
> > consistent with the posting guidelines:
>
> > An example of the search target in $form_values.... could be
> > 1224|1357|2239|2243|2468 (intended to match anywhere in the 12 unmasked
> > digits), which are actually (up to) three numbers. What I want to do is
> > insert something like (.{4}){0,2} before and after the search target (where
> > I currently have .* in my first version above) so that it only considers 4
> > digits at a time. Here is some sample data from the file.
>
> > The Brethren 20010210282239 Fa
> > Gorilla, My Love 19810211042240 HF
> > KeitaiDenwaNoHimitsu 200102110722412242 JaChCS
> > Harry Potter and the Philosopher's Stone199702111722362243 Fa
>
> > In this example the first and fourth lines are proper matches against 2239
> > and 2243, respectively, but the third line is an undesired match against
> > 1224. The problem as I see it is that the two things I'm thinking about
> > inserting should communicate with each other so that they always consume a
> > total of 8 characters, thereby forcing the target to consider only four
> > characters at a time.
>
> Try this variant:
>
> @foo2 = grep substr( $_, 50, 12 ) =~
> /^(?:\d{4}){0,2}$form_values{'a_SEARCH_VALUE'}/,
> @foo1;
>
> Essentially that ties the pattern to the beginning of the substring,
> then allows zero to two groups of four digits before a match.
>
> Anno
Sorry, but that doesn't work. I think it's because it picks up the
false matches when it has no groups of four digits before the match.
Somehow it needs to be limited to considering only four source digits
at a time, or to think that there is a non-digit boundary between the
two groups of four digits.
(I don't think it matters, and I tested it both ways, but I think it
should be
@foo2 = grep substr( $_, 50, 12 ) =~
/^(?:.{4}){0,2}$form_values{'a_SEARCH_VALUE'}/,
@foo1;
rather than your version. The data file may have spaces, and I think
that \d wouldn't count them at that point.)
I sort of like Perl, but it seems to be the case that I like it as a
mind-bending experience...
------------------------------
Date: Sun, 18 Feb 2007 02:39:00 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Regexp for email addresses.
Message-Id: <er8anv$21es$1@ns.felk.cvut.cz>
Abigail wrote:
> `` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
> `` > :: ^^^^^^^^^^^^^
> `` > ::
>
> The sig works for Perl 5.000 and all versions since.
>
I use ActivePerl 5.6.1 on Windows XP but your code still not work wor me.
I get this message
c:\>perl -wlpe '}{$_=$.}{' autoexec.bat
c:\>Useless use of a constant in void context at -e line 1.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Sat, 17 Feb 2007 20:59:13 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Regexp for email addresses.
Message-Id: <m2k5ygw7im.fsf@local.wv-www.com>
"Petr Vileta" <stoupa@practisoft.cz> writes:
> Abigail wrote:
>> `` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
>> `` > :: ^^^^^^^^^^^^^
>> `` > ::
>>
>> The sig works for Perl 5.000 and all versions since.
>>
> I use ActivePerl 5.6.1 on Windows XP but your code still not work wor me.
perldoc -q one-liners
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Sun, 18 Feb 2007 05:49:48 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Regexp for email addresses.
Message-Id: <er8luv$268s$1@ns.felk.cvut.cz>
Sherm Pendley wrote:
> "Petr Vileta" <stoupa@practisoft.cz> writes:
>
>> Abigail wrote:
>>> `` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
>>> `` > :: ^^^^^^^^^^^^^
>>> `` > ::
>>>
>>> The sig works for Perl 5.000 and all versions since.
>>>
>> I use ActivePerl 5.6.1 on Windows XP but your code still not work
>> wor me.
>
> perldoc -q one-liners
>
Yes you are right. After I change single quoute to double I got different
error message :-)
c:\>perl -wlpe "}{$_=$.}{" autoexec.bat
Unmatched right curly bracket at -e line 1, at end of line
syntax error at -e line 1, near "}"
Execution of -e aborted due to compilation errors.
c:\>
I'm writting in Perl many years and uderstand what is $_ what is $. what is
{ }, but not understand what should to do } { . What is meaning by brackets
in reverse order?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Sat, 17 Feb 2007 12:51:14 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Request for a PERL script to download files
Message-Id: <45D6FB08.D17981FE@earthlink.net>
anno4000@radom.zrz.tu-berlin.de wrote:
> I don't remember the post specifically, but I've noted my
> reactions now:
>
>
> In an HTML context, "link extraction" would mean scanning
> the pages for links. What is "link extraction" in an FTP
> context? I seriously don't know. That reduces my inclination
> to try a reply.
For instance, on this site:
ftp://ftp.FreeBSD.org/pub/FreeBSD/
I'd like to get the following links off of it:
ftp://ftp.FreeBSD.org/pub/FreeBSD/README.TXT
ftp://ftp.FreeBSD.org/pub/FreeBSD/TIMESTAMP.
etc
So I'm simply trying to get the links to the files, not
the folders, but both will do.
I guess I can save the site as a text file and search for
the file names, but surely there is a better way.
I'm trying Sherm's idea of using WWW::Mechanize.
I can get this to work:
use strict;
use warnings;
use WWW::Mechanize;
my $m = WWW::Mechanize->new;
$m->get("ftp://ftp.FreeBSD.org/pub/FreeBSD/");
print $m->content;
__________________________________-
But oddly this does not work (Can't use an undefined
value as a ARRAY reference . . . ):
use strict;
use warnings;
use WWW::Mechanize;
my $m = WWW::Mechanize->new;
$m->get("ftp://ftp.FreeBSD.org/pub/FreeBSD/");
my @links = @{$m->links};
print @links;
> > I have native perl
> > HTML extraction scripts, and I can find the
> > packaged Extract Link programs on the web, but
> > I'd like a simple script that will do the job for me.
> > I'm surprised I can't find this on my own.
>
> That part does nothing to make he question more clear.
>
> > Is Net::FTP the way to go?
>
> Probably. Why didn't you look at the documentation and
> see if it's promising? I'm not going to do it for you,
> especially not knowing what exactly you're looking for.
I did check that out, but didn't see an easy way to get the
job done. I think it's in there, but I couldn't figure it out.
------------------------------
Date: Sat, 17 Feb 2007 09:54:08 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Request for a PERL script to download files
Message-Id: <slrnete990.sng.tadmc@tadmc30.august.net>
Mike Flannigan <mikeflan@earthlink.net> wrote:
> anno4000@radom.zrz.tu-berlin.de wrote:
>
>> I don't remember the post specifically, but I've noted my
>> reactions now:
>>
>>
>> In an HTML context, "link extraction" would mean scanning
>> the pages for links. What is "link extraction" in an FTP
>> context? I seriously don't know. That reduces my inclination
>> to try a reply.
I skipped over the OP for the very same reason, I couldn't understand
the question.
But _now_ I think I've spotted where the disconnect is originating...
> For instance, on this site:
> ftp://ftp.FreeBSD.org/pub/FreeBSD/
^^^
^^^
That part of the URL is the "protocol" that is being used
(See http://en.wikipedia.org/wiki/Protocol_%28computing%29).
Note that we are NOT using http: there, so we are not expecting
a response in HTML.
Go to that URL in a browser, and do a "View Source".
See any "href" or "src" thingamabobs that might be interpreted
as a "link"?
Nope.
Mike has fallen prey to the jack-of-all-trades nature of
modern browsers. Hiding the differences between protocols
and "normalizing" them into a consistent user interface
is handy in most situtations, but it can lead to an
incomplete mental model of what is really happening.
> I'd like to get the following links off of it:
> ftp://ftp.FreeBSD.org/pub/FreeBSD/README.TXT
> ftp://ftp.FreeBSD.org/pub/FreeBSD/TIMESTAMP.
There is no such thing as a "link" in the File Transfer Protocol.
> So I'm simply trying to get the links to the files,
Since we are talking ftp here, that question makes no sense.
I figure you are asking either:
I want to find out where the files are (their path).
or
I want to _transfer_ the files.
> I guess I can save the site as a text file
I guess you didn't actually try that, since it would have
revealed that there is no HTML here...
>> > Is Net::FTP the way to go?
>>
>> Probably. Why didn't you look at the documentation and
>> see if it's promising?
> I did check that out, but didn't see an easy way to get the
> job done. I think it's in there, but I couldn't figure it out.
That's probably because you are trying to follow steps from the
HyperText Transfer Protocol when you should be following the
File Transfer Protocol instead.
In ftp-speak, you need to connect to ftp site, login, change
to directory of interest, fetch file. Those are the 4 steps
shown at the top of the Net::FTP docs.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 17 Feb 2007 09:54:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: test - disregard
Message-Id: <slrnete9a9.sng.tadmc@tadmc30.august.net>
sl123@netherlands.area <sl123@netherlands.area> wrote:
> asdfasdf
Please do not throw your litter into our newsgroup.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 148
**************************************