[31762] in Perl-Users-Digest
Perl-Users Digest, Issue: 3025 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 10 14:09:23 2010
Date: Sat, 10 Jul 2010 11:09:06 -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 Sat, 10 Jul 2010 Volume: 11 Number: 3025
Today's topics:
Re: building a hash path index? <tzz@lifelogs.com>
Re: building a hash path index? <blgl@stacken.kth.se>
Re: building a hash path index? sln@netherlands.com
How to convert link encoded by javascript command to th <pengyu.ut@gmail.com>
Re: How to up file with SFTP protocol using Windows Act <info@ttrt.mrt>
Re: How to up file with SFTP protocol using Windows Act <derykus@gmail.com>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <ralph@happydays.com>
regex Mcalpine to McAlpine <john1949@yahoo.com>
Re: regex Mcalpine to McAlpine <rvtol+usenet@xs4all.nl>
Re: regex Mcalpine to McAlpine <spamtrap@piven.net>
Re: regex Mcalpine to McAlpine <tadmc@seesig.invalid>
win32::IE Automation quick question <mulshankar@gmail.com>
Re: win32::IE Automation quick question sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 09 Jul 2010 08:47:57 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: building a hash path index?
Message-Id: <87y6dksr5e.fsf@lifelogs.com>
On Fri, 09 Jul 2010 09:10:20 +0100 bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
b> What's annoying is how trivial this is for fixed-length field lists
b> e.g. 2:
b> sub mk_2_index {
b> my ($list, $fields) = @_;
b> my $index;
b> foreach my $h (@$list) {
b> push @{$index->{$h->{$fields->[0]}}->{$h->{$fields->[1]}}}, $h;
b> }
b> return $index;
b> }
That's the right direction, but by condensing and using so many
shortcuts you've robbed yourself of the chance to see the general
solution.
An alternative would have been to use Hash::Merge; construct each
entry's tree (e.g. { 10 => { 20 => { a => 10, b => 20 } } } )
individually and merge them all into one hash. But since that will be
less efficient (I think) I went with the recursive standalone version
below. It produces the results you want and will work as long as all
the entries have the keys required.
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
my $data = [
{
a => 10,
b => 20,
},
{
a => 10,
b => 25,
c => "thing",
},
{
a => 10,
b => 25,
c => "other thing",
},
{
a => 12,
b => 25,
},
];
my $index = mk_index($data, [ 'a', 'b'] );
print Dumper($index);
sub mk_index
{
my $data = shift @_;
my $fields = shift @_;
return $data unless scalar @$fields;
my @fields = @$fields;
my $field = shift @fields;
my %uniques;
foreach my $entry (@$data)
{
push @{$uniques{$entry->{$field}}}, $entry;
}
my %h;
foreach my $unique (keys %uniques)
{
$h{$unique} = mk_index($uniques{$unique}, \@fields);
}
return \%h;
}
------------------------------
Date: Fri, 09 Jul 2010 22:10:29 +0200
From: Bo Lindbergh <blgl@stacken.kth.se>
Subject: Re: building a hash path index?
Message-Id: <i17vne$d39$1@speranza.aioe.org>
In article <87y6dksr5e.fsf@lifelogs.com>, Ted Zlatanov <tzz@lifelogs.com>
wrote:
> On Fri, 09 Jul 2010 09:10:20 +0100 bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
>
> b> What's annoying is how trivial this is for fixed-length field lists
> b> e.g. 2:
>
> b> sub mk_2_index {
> b> my ($list, $fields) = @_;
> b> my $index;
> b> foreach my $h (@$list) {
> b> push @{$index->{$h->{$fields->[0]}}->{$h->{$fields->[1]}}}, $h;
> b> }
> b> return $index;
> b> }
>
> That's the right direction, but by condensing and using so many
> shortcuts you've robbed yourself of the chance to see the general
> solution.
>
> An alternative would have been to use Hash::Merge; construct each
> entry's tree (e.g. { 10 => { 20 => { a => 10, b => 20 } } } )
> individually and merge them all into one hash. But since that will be
> less efficient (I think) I went with the recursive standalone version
> below. It produces the results you want and will work as long as all
> the entries have the keys required.
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> use Data::Dumper;
>
> my $data = [
> {
> a => 10,
> b => 20,
> },
> {
> a => 10,
> b => 25,
> c => "thing",
> },
> {
> a => 10,
> b => 25,
> c => "other thing",
> },
> {
> a => 12,
> b => 25,
> },
> ];
>
> my $index = mk_index($data, [ 'a', 'b'] );
> print Dumper($index);
>
> sub mk_index
> {
> my $data = shift @_;
> my $fields = shift @_;
>
> return $data unless scalar @$fields;
>
> my @fields = @$fields;
> my $field = shift @fields;
>
> my %uniques;
> foreach my $entry (@$data)
> {
> push @{$uniques{$entry->{$field}}}, $entry;
> }
>
> my %h;
>
> foreach my $unique (keys %uniques)
> {
> $h{$unique} = mk_index($uniques{$unique}, \@fields);
> }
>
> return \%h;
> }
No need for recursion.
sub mk_index
{
my($data, $fields) = @_;
my(@firstfields, $lastfield, %result);
@firstfields = @{$fields};
$lastfield = pop(@firstfields);
return $data unless defined($lastfield);
foreach my $entry (@{$data}) {
my($walk);
$walk = \%result;
foreach my $field (@firstfields) {
$walk = $walk->{$entry->{$field}} ||= {};
}
push(@{$walk->{$entry->{$lastfield}}}, $entry);
}
return \%result;
}
Any more contestants, or is it time to use Benchmark qw(cmpthese)? :-)
/Bo Lindbergh
------------------------------
Date: Fri, 09 Jul 2010 16:05:52 -0700
From: sln@netherlands.com
Subject: Re: building a hash path index?
Message-Id: <3paf36h760d6lnbn0f5vhnmu3mmduks778@4ax.com>
On Fri, 09 Jul 2010 22:10:29 +0200, Bo Lindbergh <blgl@stacken.kth.se> wrote:
>
>No need for recursion.
>
>sub mk_index
>{
> my($data, $fields) = @_;
> my(@firstfields, $lastfield, %result);
>
> @firstfields = @{$fields};
> $lastfield = pop(@firstfields);
> return $data unless defined($lastfield);
> foreach my $entry (@{$data}) {
> my($walk);
>
> $walk = \%result;
> foreach my $field (@firstfields) {
> $walk = $walk->{$entry->{$field}} ||= {};
> }
> push(@{$walk->{$entry->{$lastfield}}}, $entry);
> }
> return \%result;
>}
>
>Any more contestants, or is it time to use Benchmark qw(cmpthese)? :-)
>
>
>/Bo Lindbergh
Fire away!
------------------------------
Date: Sat, 10 Jul 2010 10:29:58 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How to convert link encoded by javascript command to the actual url?
Message-Id: <10b98c25-4542-4b8a-bd69-79082878de12@w12g2000yqj.googlegroups.com>
Suppose I see a webpage on a website that has the following link
encoded by javascript, I want to user perl to parse such webpage and
convert it to the actual url. Could you please let me know what
package I should use? I thought that HTML package may not handle this.
But please let me know if I'm wrong.
<a herf="javascript:some_command_return_a_url();">Link</a>
------------------------------
Date: Fri, 9 Jul 2010 22:26:08 +0200
From: "Trta" <info@ttrt.mrt>
Subject: Re: How to up file with SFTP protocol using Windows Activestate perl?
Message-Id: <i180lm$1j0$1@localhost.localdomain>
Unfortunately don't work.
Perl Code:
-------------------------------------------------
#!/usr/bin/perl -w
use strict;
use warnings;
use Net::SFTP;
my $server="xxx.com";
my $user="user";
my $password="password";
my %args = (user => "$user", password => "$password", ssh_args => [port =>
22]);
my $file="TEST.CSV";
my $sftp=Net::SFTP->new($server, %args);
$sftp->put($file);
exit;
-------------------------------------------------
Message is:
The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/Perl.pm
line 110.
"Sherm Pendley" <spamtrap@shermpendley.com> wrote in message
news:m2aaq9505u.fsf@shermpendley.com...
> "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> writes:
>
>> info@potop.hr wrote:
>>> How to use SFTP protocol with Activestate perl?
>>>
>>> Please help me
>>
>> You can help yourself and greatly cut down the time it takes
>> for you to possibly find a solution, by first trying to find
>> the information on your own.
>>
>> Put "perl sftp" into your favorite search engine and you should find
>> many helpful pages.
>>
>> Oh look.. the very first result from the search is for:
>>
>> http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm
>>
>> which looks pretty useful.
>
> On the other paw, if you're trying that module and having problems
> with it, you should say so and describe the problems.
>
> sherm--
>
> --
> Sherm Pendley <www.shermpendley.com>
> <www.camelbones.org>
> Cocoa Developer
>
> __________ Information from ESET Smart Security, version of virus
> signature database 5246 (20100702) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
__________ Information from ESET Smart Security, version of virus signature database 5266 (20100709) __________
The message was checked by ESET Smart Security.
http://www.eset.com
------------------------------
Date: Fri, 9 Jul 2010 21:29:56 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: How to up file with SFTP protocol using Windows Activestate perl?
Message-Id: <33bfeefa-3199-4a37-b295-2741a9219c30@s17g2000prh.googlegroups.com>
On Jul 9, 1:26=A0pm, "Trta" <i...@ttrt.mrt> wrote:
> Unfortunately don't work.
>
> ...
> -------------------------------------------------
> Message is:
> The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/Perl.p=
m
> line 110.
>
> ...
See:
http://www.mail-archive.com/activeperl@listserv.activestate.com/msg23275.ht=
ml
--
Charles DeRykus
------------------------------
Date: Fri, 09 Jul 2010 10:59:51 -0400
From: Ralph Malph <ralph@happydays.com>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
Message-Id: <8e1c$4c373967$40779ac3$24843@news.eurofeeds.com>
tl, dnr
------------------------------
Date: Sat, 10 Jul 2010 10:38:00 +0100
From: "John" <john1949@yahoo.com>
Subject: regex Mcalpine to McAlpine
Message-Id: <i19f1m$nbf$1@news.albasani.net>
Hi
I've reduced some text to upper and lower case.
Some names need uppercase within the word. Mcalpine would be McAlpine.
I need to use the uc function within the regex expression.
$x=~ s| Mc([A-Z]{1})| Mcuc($1) |g;
The above clearly does not work. How do you insert a function in such an
expression?
Regards
John
------------------------------
Date: Sat, 10 Jul 2010 12:09:46 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: regex Mcalpine to McAlpine
Message-Id: <4c3846ea$0$22916$e4fe514c@news.xs4all.nl>
John wrote:
> I need to use the uc function within the regex expression.
>
> $x=~ s| Mc([A-Z]{1})| Mcuc($1) |g;
>
> The above clearly does not work. How do you insert a function in such an
> expression?
That is an XY problem. http://www.google.co.uk/#hl=en&q=xy+problem
Look ma, no function:
s/(?<= Mc)([a-z])/\u$1/g;
To find out how to use a function though, checkout the e-modifier in
`perldoc perlre`. There is also perlretut.
--
Ruud
------------------------------
Date: Sat, 10 Jul 2010 07:13:16 -0500
From: Don Piven <spamtrap@piven.net>
Subject: Re: regex Mcalpine to McAlpine
Message-Id: <O5CdnSyTi7VE_qXRnZ2dnUVZ_g2dnZ2d@speakeasy.net>
On 07/10/2010 04:38 AM, John wrote:
> I've reduced some text to upper and lower case.
>
> Some names need uppercase within the word. Mcalpine would be McAlpine.
>
> I need to use the uc function within the regex expression.
>
> $x=~ s| Mc([A-Z]{1})| Mcuc($1) |g;
>
> The above clearly does not work. How do you insert a function in such an
> expression?
What you could do in this case is to use the /e switch, which causes the
right side to be eval'ed:
$x =~ s| Mc([a-z]{1}) | "Mc".uc($1) |ex ;
(Oh, fixed those other two bugs for ya :-)
Don Piven
------------------------------
Date: Sat, 10 Jul 2010 10:02:56 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: regex Mcalpine to McAlpine
Message-Id: <slrni3h2md.q11.tadmc@tadbox.sbcglobal.net>
John <john1949@yahoo.com> wrote:
> I need to use the uc function within the regex expression.
You are NOT using the uc function within the regex expression below!
Perl's operators that use regular expressions are documented
in the "Regexp Quote-Like Operators" section in:
perldoc perlop
For the s/// operator it says:
s/PATTERN/REPLACEMENT/msixpogce
PATTERN is a regex, REPLACEMENT is a string (ie. not a regex).
> $x=~ s| Mc([A-Z]{1})| Mcuc($1) |g;
You are using the uc function in the _replacment_ part of the
s/// operator.
> The above clearly does not work. How do you insert a function in such an
> expression?
If you carefully read the documentation for the function, you will
discover that you do not need a function. You can use a backslash
escape to affect case.
perldoc -f uc
perldoc -f ucfirst
So then,
s/\bMc([a-z])/Mc\U$1/;
or
s/(?<=\bMc)([a-z])/\U$1/;
Good luck getting MacArthur from Macarthur without also getting
MacHine from Machine...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Fri, 9 Jul 2010 08:12:44 -0700 (PDT)
From: shankar_perl_rookie <mulshankar@gmail.com>
Subject: win32::IE Automation quick question
Message-Id: <22d247f3-ce31-4949-89e2-34918fe10cd1@j8g2000yqd.googlegroups.com>
Hello All,
I am looking to automate IE using this package and I am having trouble
with this particular point where I need to click a button. The page
source for the button has the following properties:
<div class="search_builder_submit"><div
id="view:_id1:_id204:showBody:_id206:searchSubmit" style="width:142px;
cursor:pointer; float:left"><img src="b_search.png"></div>
The point is there is no name, title or value options for which
generally the click button reacts to.. I have tried using the id but
get an error saying that the click option doesn't know what to do....
Any help would be appreciated !
Regards,
------------------------------
Date: Fri, 09 Jul 2010 11:15:04 -0700
From: sln@netherlands.com
Subject: Re: win32::IE Automation quick question
Message-Id: <u3pe36hq17j321ro78e0g2k5t91dg6u40r@4ax.com>
On Fri, 9 Jul 2010 08:12:44 -0700 (PDT), shankar_perl_rookie <mulshankar@gmail.com> wrote:
>Hello All,
>
>I am looking to automate IE using this package and I am having trouble
>with this particular point where I need to click a button. The page
>source for the button has the following properties:
>
><div class="search_builder_submit"><div
>id="view:_id1:_id204:showBody:_id206:searchSubmit" style="width:142px;
>cursor:pointer; float:left"><img src="b_search.png"></div>
>
>The point is there is no name, title or value options for which
>generally the click button reacts to.. I have tried using the id but
>get an error saying that the click option doesn't know what to do....
>Any help would be appreciated !
>
>Regards,
Is this a Perl problem? Have you checked the html?
I'm not a web designer so in my uneducated state
I'd say the id isin't being used. Have you tried to
put the html in a TryIt window at w3schools?
Being a rookie, I put together a test html,
try it out. Paste it into the left window here:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick
For any attribute that does not exist,
I think the variable (in JS) is assigned ''.
Add a value='' attribute then try it again.
-sln
----------------
<html>
<body>
<div class="search_builder_submit">
<div id="view:_id1:_id204:showBody:_id206:searchSubmit"
</div>
<!--
<div id="view:_id1:_id204:showBody:_id206:searchSubmit"
value="Hello World!" >
</div>
-->
</div>
<br />
Box: <input type="text" id="box" />
<br /><br />
Click the button to copy the content of
id = "view:_id1:_id204:showBody:_id206:searchSubmit"
to the Edit Box.
<br />
<button onclick=
"
v = document.getElementById
('view:_id1:_id204:showBody:_id206:searchSubmit').value;
document.getElementById('box').value = v ? v : 'NO VALUE!';
">
Copy It!
</button>
</body>
</html>
------------------------------
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 3025
***************************************