[26510] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8666 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 15 00:05:35 2005

Date: Mon, 14 Nov 2005 21:05:05 -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, 14 Nov 2005     Volume: 10 Number: 8666

Today's topics:
        Getting a list of all current variables in a Perl progr <jkeen_via_google@yahoo.com>
    Re: Inject fresh variable in scope <sdn.girths00869@zoemail.net>
    Re: Inject fresh variable in scope (See Website For Email)
    Re: Pattern Matching problem! <1usa@llenroc.ude.invalid>
    Re: Pattern Matching problem! <abigail@abigail.nl>
    Re: Pattern Matching problem! <1usa@llenroc.ude.invalid>
    Re: Pattern Matching problem! <noreply@gunnar.cc>
        regexp that matches half then conditionally excludes th <dont_w@nt_spam.org>
    Re: regexp that matches half then conditionally exclude <cwilbur@chromatico.net>
    Re: regexp that matches half then conditionally exclude <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 15 Nov 2005 03:23:24 GMT
From: James E Keenan <jkeen_via_google@yahoo.com>
Subject: Getting a list of all current variables in a Perl program
Message-Id: <Mwcef.112$Ov1.1@trndny08>

 From a 1997 posting by Randal L Schwartz on this list, I got the 
following code as a way to get a list of all (or most ??) identifiers in 
a program at a given point.

    print  "\n\n" .
        Dumper ({
                 map {
                   (defined $$_ ? ("\$$_" => $$_) : ()),
                   (defined @$_ ? ("\@$_" => \@$_) : ()),
                   (defined %$_ ? ("\%$_" => \%$_) : ()),
                 } sort keys %{__PACKAGE__."::"}
                });

1.  Are there any better ways to approach this problem?
2.  In addition to package variables, how can I get a list of the 
lexical variables declared at a given point in a program?  (I think this 
means the content of the scratchpad(s)?)

TIA

Jim Keenan


------------------------------

Date: Mon, 14 Nov 2005 17:16:34 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Inject fresh variable in scope
Message-Id: <Xns970EBA147CE00sdn.comcast@216.196.97.136>

brianr@liffe.com wrote in news:vtwtjbp494.fsf@ssdevws28.admin.liffe.com:

> ISTM that it could be done with a source filter
> 
> 

Hmmm, that's not a bad idea.  I must explore that.

-- 
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`


------------------------------

Date: Mon, 14 Nov 2005 19:19:59 -0800
From: "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@moderncppdesign.com>
To:  brianr@liffe.com
Subject: Re: Inject fresh variable in scope
Message-Id: <437953DF.6020806@moderncppdesign.com>

brianr@liffe.com wrote:
> ISTM that it could be done with a source filter e.g.

(snip)

Thanks! Interesting idea; I got it to work, but then I noticed someone 
has written something along the same lines:

http://search.cpan.org/~abergman/Hook-Scope-0.04/Scope.pm

Now, I tried to install that, and found out it depends on a zillion 
other modules. Now, the question is: is there a simple way to manage 
dependencies in Perl - i.e., download a package and all of its 
dependents from somewhere? Thanks!


Andrei


------------------------------

Date: Mon, 14 Nov 2005 23:20:00 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Pattern Matching problem!
Message-Id: <Xns970EBA81F5AA9asu1cornelledu@127.0.0.1>

"Francis Sylvester" <francis@nospam.com> wrote in
news:AH8ef.16551$Es4.9736@fe2.news.blueyonder.co.uk: 

> I'm a Perl newbie and am having a nightmare trying to get the code
> below working. I'm trying to fetch a webpage and if a link within the
> page matches the search criterion - return the text after the link. It
> doesn't seem to be working and I'm wondering

As it is, we have no idea "doesn't seem to be working means". Please 
read the posting guidelines to find out how you can help yourself, and, 
in the process, help others help you.

use strict;
use warnings;

missing.

> use LWP::Simple;
> use HTML::TokeParser;
> 
> my $document = get("http://www.anexamplesite.com");
> my $mymatch = "searchstring";
> 
> my $parser = HTML::TokeParser->new(\$document);
> 
> while ($token = $parser->get_tag("a")) {
>          if ($token->[1]->{"href"} =~ /$mymatch/) {
> #            print $server.$token->[1]->{href}."\n";
>               $document =~ /$searchstring(.+?)someidentifier/;

The exact contents of $mymatch, $searchstring and whatever 
someidentifier might have something to do with what's actually being 
matched, no?

>                print "$1";

You are not capturing anything, why do you expect there to be anything 
valid in $1?

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 15 Nov 2005 00:10:07 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Pattern Matching problem!
Message-Id: <slrndni9qv.2l3.abigail@alexandra.abigail.nl>

A. Sinan Unur (1usa@llenroc.ude.invalid) wrote on MMMMCDLVIII September
MCMXCIII in <URL:news:Xns970EBA81F5AA9asu1cornelledu@127.0.0.1>:
:)  "Francis Sylvester" <francis@nospam.com> wrote in
:)  news:AH8ef.16551$Es4.9736@fe2.news.blueyonder.co.uk: 
:)  
:) > I'm a Perl newbie and am having a nightmare trying to get the code
:) > below working. I'm trying to fetch a webpage and if a link within the
:) > page matches the search criterion - return the text after the link. It
:) > doesn't seem to be working and I'm wondering
:)  
:)  As it is, we have no idea "doesn't seem to be working means". Please 
:)  read the posting guidelines to find out how you can help yourself, and, 
:)  in the process, help others help you.
:)  
:)  use strict;
:)  use warnings;
:)  
:)  missing.
:)  
:) > use LWP::Simple;
:) > use HTML::TokeParser;
:) > 
:) > my $document = get("http://www.anexamplesite.com");
:) > my $mymatch = "searchstring";
:) > 
:) > my $parser = HTML::TokeParser->new(\$document);
:) > 
:) > while ($token = $parser->get_tag("a")) {
:) >          if ($token->[1]->{"href"} =~ /$mymatch/) {
:) > #            print $server.$token->[1]->{href}."\n";
:) >               $document =~ /$searchstring(.+?)someidentifier/;
:)  
:)  The exact contents of $mymatch, $searchstring and whatever 
:)  someidentifier might have something to do with what's actually being 
:)  matched, no?
:)  
:) >                print "$1";
:)  
:)  You are not capturing anything, why do you expect there to be anything 
:)  valid in $1?


Not capturing? I'd say the parens in /$searchstring(.+?)someidentifier/
capture (if the match is succesful), or there's a bug in perl.



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


------------------------------

Date: Tue, 15 Nov 2005 02:28:56 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Pattern Matching problem!
Message-Id: <Xns970EDA8831638asu1cornelledu@127.0.0.1>

Abigail <abigail@abigail.nl> wrote in
news:slrndni9qv.2l3.abigail@alexandra.abigail.nl: 

> A. Sinan Unur (1usa@llenroc.ude.invalid) wrote on MMMMCDLVIII
> September MCMXCIII in
> <URL:news:Xns970EBA81F5AA9asu1cornelledu@127.0.0.1>: 
>:)  "Francis Sylvester" <francis@nospam.com> wrote in
>:)  news:AH8ef.16551$Es4.9736@fe2.news.blueyonder.co.uk: 

 ...

>:) >               $document =~ /$searchstring(.+?)someidentifier/;
>:)  
>:)  The exact contents of $mymatch, $searchstring and whatever 
>:)  someidentifier might have something to do with what's actually
>:)  being matched, no?
>:)  
>:) >                print "$1";
>:)  
>:)  You are not capturing anything, why do you expect there to be
>:)  anything valid in $1?


> Not capturing? I'd say the parens in 
> /$searchstring(.+?)someidentifier/ capture (if the match is 
> succesful), or there's a bug in perl.

Arrgh! Thank you very much for catching that.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Tue, 15 Nov 2005 04:30:18 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Pattern Matching problem!
Message-Id: <3tt32bFuc89aU1@individual.net>

Francis Sylvester wrote:
> I'm a Perl newbie and am having a nightmare trying to get the code below 
> working. I'm trying to fetch a webpage and if a link within the page matches 
> the search criterion - return the text after the link.
> 
> use LWP::Simple;
> use HTML::TokeParser;

Yes, using a module for parsing an HTML document is a good idea.

> my $document = get("http://www.anexamplesite.com");
> my $mymatch = "searchstring";
> 
> my $parser = HTML::TokeParser->new(\$document);
> 
> while ($token = $parser->get_tag("a")) {
>          if ($token->[1]->{"href"} =~ /$mymatch/) {
> #            print $server.$token->[1]->{href}."\n";
>               $document =~ /$searchstring(.+?)someidentifier/;

What's that? After you have possibly found your search string, you let 
the program search the whole document using a simple regex. Doing so 
makes no sense to me.

Either you'd better stick to a simple regex, and skip the parsing 
module, or (better) taking advantage of the module you are using, and 
doing something like:

     while ( my $token = $parser->get_tag('a') ) {
         if ($token->[1]{href} =~ /$mymatch/) {
             print $parser->get_text('a')."\n";
         }
     }

(I'm not sure if that's what you're looking for, but hopefully you get 
the idea.)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Tue, 15 Nov 2005 03:09:23 GMT
From: Mike Ballard <dont_w@nt_spam.org>
Subject: regexp that matches half then conditionally excludes the other half
Message-Id: <m23bly7gi9.fsf@west_f1.net>


I have to search for string pairs such as "Kc Qd" and "Qh Ks" and am
having a problem figuring out a regexp that will exclude (for example):

 "Kd Qd"
 "Kd Kc"
 "Qd Qh"
 "Qh Kh"

IOW, both uppercase letters in each pair must be unique (discard "Kx Kx",
"Qx Qx") and the lowercase letters for each pair must be unique (discard
"Ks Qs", "Qc Kc", etc.).  The range of lowercase letters is "cdhs".

So if the first part of a pair is "Kh" and the second part is "Kx" or
"Qh", the whole thing needs to be skipped and I move on to the next one.

Can someone tell me how to do this (it's in a perl script btw)?

Mike
-- 



------------------------------

Date: Mon, 14 Nov 2005 22:39:47 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: regexp that matches half then conditionally excludes the other half
Message-Id: <m2lkzq60l8.fsf@ubiquity.chromatico.net>

>>>>> "MB" == Mike Ballard <dont_w@nt_spam.org> writes:

    MB> Can someone tell me how to do this (it's in a perl script
    MB> btw)?

Why do you insist on doing it entirely with a regular expression?
Make the logic explicit, and it will be that much easier to write and
to maintain.

if (/([KQ])([cdhs]) ([KQ])([cdhs])/ && $1 ne $3 && $2 ne $4)
{
 ...
}

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


------------------------------

Date: Tue, 15 Nov 2005 03:42:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: regexp that matches half then conditionally excludes the other half
Message-Id: <Xns970EE6FA9ED34asu1cornelledu@127.0.0.1>

Mike Ballard <dont_w@nt_spam.org> wrote in
news:m23bly7gi9.fsf@west_f1.net: 

> I have to search for string pairs such as "Kc Qd" and "Qh Ks" and am
> having a problem figuring out a regexp that will exclude (for
> example): 
> 
>  "Kd Qd"
>  "Kd Kc"
>  "Qd Qh"
>  "Qh Kh"
> 
> IOW, both uppercase letters in each pair must be unique (discard "Kx
> Kx", "Qx Qx") and the lowercase letters for each pair must be unique
> (discard "Ks Qs", "Qc Kc", etc.).  The range of lowercase letters is
> "cdhs". 
> 
> So if the first part of a pair is "Kh" and the second part is "Kx" or
> "Qh", the whole thing needs to be skipped and I move on to the next
> one. 
> 
> Can someone tell me how to do this (it's in a perl script btw)?

By writing it, of course.

use strict;
use warnings;

while (<DATA>) {
   if (m{([KQ])([cdhs]) ([KQ])([cdhs])}) {
      if ($1 ne $3 and $2 ne $4) {
         print "$1$2 $3$4\n";
      }
   }
}


__DATA__
Kd Qd
Kd Kc
Qd Qh
Qh Kh
Kd Qc



-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.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:

#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 V10 Issue 8666
***************************************


home help back first fref pref prev next nref lref last post