[17925] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 85 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 17 21:10:40 2001

Date: Wed, 17 Jan 2001 18:10:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979783812-v10-i85@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 17 Jan 2001     Volume: 10 Number: 85

Today's topics:
    Re: regular expression question. pls help (Tad McClellan)
    Re: regular expression question. pls help vupt@yahoo.com
    Re: regular expression question. pls help (Ben Okopnik)
    Re: regular expression question. pls help <usequity@mindspring.com>
    Re: regular expression question. pls help (Tad McClellan)
    Re: regular expression question. pls help (Tad McClellan)
    Re: Run perl from a Perl script ? How ? (Tad McClellan)
        Running a CGI as a USER <seppanen@chartermi.net>
    Re: Running htpasswd with Perl <tony_curtis32@yahoo.com>
        Sorting complex data structure <artd@artd3.com>
    Re: Sorting complex data structure (Damian James)
    Re: String eq problem <mjcarman@home.com>
    Re: String eq problem <ren.maddox@tivoli.com>
    Re: Syntax -  Still need HELP <ren.maddox@tivoli.com>
    Re: What do you call the => operator? (David H. Adler)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 17 Jan 2001 23:35:49 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expression question. pls help
Message-Id: <slrn96c3a3.2v4.tadmc@tadmc26.august.net>

vupt@yahoo.com <vupt@yahoo.com> wrote:
>
>Supposing I have the following data  :
>
><item delimiter=", " name="UPT
>PIR"><value>http://www.uptpir.com/products/index.html</value></item>
    ^^
    ^^

>the regular expression I am using right now is
>
>my $matchKey="UPT PIR[ .]*?<value>(.*)</value>";
                      ^^^^^^       ^^^^  you want non-greedy there too

That matches only dot and space characters. Your string has a
double quote and an angle bracket there, so the match must fail.

Is there some reason why the below won't work?

   my $matchKey = "UPT PIR\"><value>(.*?)</value>";  # worst

or

   my $matchKey = qq!UPT PIR"><value>(.*?)</value>!; # better

or

   my $matchKey = 'UPT PIR"><value>(.*?)</value>';   # best


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 18 Jan 2001 00:03:19 GMT
From: vupt@yahoo.com
Subject: Re: regular expression question. pls help
Message-Id: <945bs2$t85$1@nnrp1.deja.com>

Hi,

I seem to be able to get it to work with the following:
my $matchKey="UPT PIR.*?<value>(.*?)</value>";
	if ($line=~/$matchKey/) {
	     print "match: $1\n";
        return 1;
   } else {
	     print "no match\n";
        return 0;
   }

In article <9454hp$mdd$1@nnrp1.deja.com>,
  vupt@yahoo.com wrote:
> Hi,
>
> I'm having a perl regular expression problem and am hoping someone can
> give me a hand.
>
> Supposing I have the following data  :
>
> <item delimiter=", " name="UPT
> PIR"><value>http://www.uptpir.com/products/index.html</value></item>
>
> There are many items but the item that I want has name attribute with
> value "UPT PIR"
> I would like to extract the content between <value></value> and so for
> the above example,
> http://www.uptpir.com/products/index.html would be the value
extracted.
>
> the regular expression I am using right now is
>
> my $matchKey="UPT PIR[ .]*?<value>(.*)</value>";
> 	if ($line=~/$matchKey/) {
> 	     print "match $1\n";
>    } else {
> 	     print "no match\n";
>    }
>
> If anyone can give me a hand, it would be so appreciated.
>
> Sent via Deja.com
> http://www.deja.com/
>


Sent via Deja.com
http://www.deja.com/


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

Date: 18 Jan 2001 00:17:49 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: regular expression question. pls help
Message-Id: <slrn96cdn0.2b5.ben-fuzzybear@Odin.Thor>

The ancient archives of Wed, 17 Jan 2001 23:35:49 GMT showed
Tad McClellan of comp.lang.perl.misc speaking thus:
>
>That matches only dot and space characters. Your string has a
>double quote and an angle bracket there, so the match must fail.
>
>Is there some reason why the below won't work?
>
>   my $matchKey = "UPT PIR\"><value>(.*?)</value>";  # worst
>
>or
>
>   my $matchKey = qq!UPT PIR"><value>(.*?)</value>!; # better
>
>or
>
>   my $matchKey = 'UPT PIR"><value>(.*?)</value>';   # best


Why are the above "graded" that way? I just see them as TMTOWTDI; I don't 
think that there's any functional difference (and please do correct me if 
I'm wrong.) Is it a matter of 'proper style'?


Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The best way to escape from a problem is to solve it. -- Alan Saporta


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

Date: Thu, 18 Jan 2001 00:20:06 GMT
From: "Henry" <usequity@mindspring.com>
Subject: Re: regular expression question. pls help
Message-Id: <WEq96.62482$ge4.23986054@news2.rdc2.tx.home.com>

You may need to escape the / in </value>. Also, because of greediness, your
(.*) will match everything through the last </value> in the file.  You may
be able to use ([^<]) instead, but someone in this group may have a prettier
solution.

YAPH
Henry


<vupt@yahoo.com> wrote in message news:9454hp$mdd$1@nnrp1.deja.com...
> Hi,
>
> I'm having a perl regular expression problem and am hoping someone can
> give me a hand.
>
> Supposing I have the following data  :
>
> <item delimiter=", " name="UPT
> PIR"><value>http://www.uptpir.com/products/index.html</value></item>
>
> There are many items but the item that I want has name attribute with
> value "UPT PIR"
> I would like to extract the content between <value></value> and so for
> the above example,
> http://www.uptpir.com/products/index.html would be the value extracted.
>
> the regular expression I am using right now is
>
> my $matchKey="UPT PIR[ .]*?<value>(.*)</value>";
> if ($line=~/$matchKey/) {
>      print "match $1\n";
>    } else {
>      print "no match\n";
>    }
>
> If anyone can give me a hand, it would be so appreciated.




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

Date: Wed, 17 Jan 2001 18:37:24 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expression question. pls help
Message-Id: <slrn96cb5k.33r.tadmc@tadmc26.august.net>

Ben Okopnik <ben-fuzzybear@geocities.com> wrote:
>The ancient archives of Wed, 17 Jan 2001 23:35:49 GMT showed
>Tad McClellan of comp.lang.perl.misc speaking thus:
>>
>>That matches only dot and space characters. Your string has a
>>double quote and an angle bracket there, so the match must fail.
>>
>>Is there some reason why the below won't work?
>>
>>   my $matchKey = "UPT PIR\"><value>(.*?)</value>";  # worst
>>
>>or
>>
>>   my $matchKey = qq!UPT PIR"><value>(.*?)</value>!; # better
>>
>>or
>>
>>   my $matchKey = 'UPT PIR"><value>(.*?)</value>';   # best
>
>
>Why are the above "graded" that way? I just see them as TMTOWTDI; 


I see a progression in how communicative each is.

I'm just leaving bread crumbs to follow when I have to return
to the code after not seeing it for a long time.

I am most often looking for variables when debugging. With the
"best" method, I have to read less than half of the line
('til when I see the single quote) to determine that I can
go to the next line. With the other two I have to carefully
examine the entire line.

I'm lazy and impatient.


>I don't 
>think that there's any functional difference (and please do correct me if 
>I'm wrong.) 


No correction necessary (for the given string).

I do not use double quotes unless I need one of the 2 things that
they give you over single quotes, so I always use single quotes
for constant strings (unless I need backslash escape chars). 


>Is it a matter of 'proper style'?


Yes. It is a matter of _my_ style, so I get to plug it in my answers :-)

Not to say that my style is "proper".  In fact, I have seen more 
than one Guru (and I know when to use that term) disagree with my 
style of quoting. I remain unconvinced.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 17 Jan 2001 18:23:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expression question. pls help
Message-Id: <slrn96cac5.33r.tadmc@tadmc26.august.net>


[ Jeopardectomy performed ]


Henry <usequity@mindspring.com> wrote:
><vupt@yahoo.com> wrote in message news:9454hp$mdd$1@nnrp1.deja.com...

>> my $matchKey="UPT PIR[ .]*?<value>(.*)</value>";
>> if ($line=~/$matchKey/) {

>You may need to escape the / in </value>.
     ^^^
     ^^^ please don't post guesses


You do not need to escape the / in </value>.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 17 Jan 2001 23:35:50 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Run perl from a Perl script ? How ?
Message-Id: <slrn96c41v.2v4.tadmc@tadmc26.august.net>

DarrenDeans@Hotmail.com <DarrenDeans@Hotmail.com> wrote:
>Can anybody tell me how to run a perl script from a perl script ?

Here is one way:

   system "perl script";

There are some other ways of running external programs whether
written in Perl or some other language.

   perldoc -q external

will describe those for you.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 17 Jan 2001 20:55:47 -0500
From: "Brian E. Seppanen" <seppanen@chartermi.net>
Subject: Running a CGI as a USER
Message-Id: <3A664D23.16EB8C8B@chartermi.net>

Hello:

I've been given the task of setting up a user guestbook on a multi-user
webserver running linux and apache 1.3.14.  The criteria I have been
given is that I need to setuid the program and run the program as the
user.  Now I'm very new to writing perl, and CGI's.  I'm trying to do
this as securely as possible.  My initial thoughts were rw-rw-rw the
damn guestbook and let the script run as nobody and I'm hesitant of
setuiding a script.  So anyways the thinking is that the script is
setuid, we match the username, test it for validity, once we've
determined the username we somehow send the script off as user A giving
it the effective rights of the user.  Now I'm not sure how I would do
this.  Would I have to fork a new process?  Would it be as easy as
defining $EFFECTIVE_USER_ID=(getpwnam($username)) [3];  Although I've
tried that it doesn't seem to work.   Doing it this way would allow  the
guestbook to be rw-r--r--.  Not just anyone could write to it.

I really don't know whether this is more of an apache issue or a perl
issue.

Hope someone can shed a little light on this.

Brian E. Seppanen



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

Date: 17 Jan 2001 17:50:21 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Running htpasswd with Perl
Message-Id: <87n1cpivr6.fsf@limey.hpcc.uh.edu>

>> On Wed, 17 Jan 2001 22:34:03 GMT,
>> xlr6drone@my-deja.com said:

> Hello all, I am wondering if it is possiblle to run
> htpasswd (and setup up a username and password for
> .htaccess) by running a process to the shell.

Yes it is, but you're solving the wrong problem.

htpasswd is a command-line utility whose purpose is to
manipulate authentication repositories for a web server.

Perl can do this directly:

    perldoc HTTPD::UserAdmin

hth
t
-- 
Eih bennek, eih blavek.


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

Date: Wed, 17 Jan 2001 16:40:41 -0500
From: "Art" <artd@artd3.com>
Subject: Sorting complex data structure
Message-Id: <t6cglljs8jo382@corp.supernews.com>

I have a data structure listed as such:

%Records = (
    "Username" => {
        Last_Name => "$Last_Name",
        First_Name => "$First_Name",
        Email =            "$Email);
    },
 ...
 etc..


I want to run through and sort the hash by the last name, I've tried a
number of sort tactics, but I am only able to sort by the first level keys.

Thanks in advance for any pointers / advice.
This was my last iteration, it is GODLY wrong, but I am so confused with t
foreach my $key (sort { sort { lc($Records{$key}{'sn'}{$a}) cmp
lc($Records{$key}{'sn'}{$b}) } keys %{ $Records{$keys}{'sn'} } } keys
%Records) {




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

Date: 18 Jan 2001 01:58:23 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: Sorting complex data structure
Message-Id: <slrn96cjfe.4tn.damian@puma.qimr.edu.au>

Art posted the following to comp.lang.perl.misc 
on Wed, 17 Jan 2001 16:40:41 -0500:
>I have a data structure listed as such:
>
>%Records = (
>    "Username" => {
>        Last_Name => "$Last_Name",
>        First_Name => "$First_Name",
>        Email =            "$Email);
>    },
>...
> etc..

Is this right? Are you sure it shouldn't be something like:

my @records = (
	{ 
		Username => { 
			Last_Name 	=> "$Last_Name",
	        First_Name 	=> "$First_Name",
	        Email 		=  "$Email"
	    },
		Other_attributes => {
			shoesize	=>	"etc"
		}
	},
	{   Username => 'etc' },
);

Or is there really only one record?

>
>I want to run through and sort the hash by the last name, I've tried a
>number of sort tactics, but I am only able to sort by the first level keys.

Probably this is not what you want to do - it doesn't make sense to sort a
hash (see perldata). 

If you agree that the data structure should be as I suggested above, then the
sort should be fairly straightforward. See perldoc -f sort for details. For 
the above, it would look something like:

@records = sort { lc($a->{Username}->{Last_name}) 
				 			 cmp 
				  lc($b->{Username}->{Last_name}) }, @records;


Cheers,
Damian


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

Date: Wed, 17 Jan 2001 16:40:42 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: String eq problem
Message-Id: <3A661F6A.D140B740@home.com>

Ron Grabowski wrote:
> 
> Ren Maddox wrote:
>>
>>     if(/<Member number=".*" status=".*">/) {
>
> /<Member number=".*?" status=".*?">/
> 
> Without the first question mark, $1 will contain everything till the
> last quotation mark.

No, it won't. For one thing, there are no backreferences, so $1 won't
changed one bit from whatever it was. I think you meant to say that the
first .* will gobble up everything to the end of the line, but that's
not right either. While it will initially gulp up whatever is left, the
regex engine will backtrack when it fails to match the entire pattern. 

-mjc


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

Date: 17 Jan 2001 17:46:13 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: String eq problem
Message-Id: <m3puhlvj22.fsf@dhcp11-177.support.tivoli.com>

Ron Grabowski <ronnie@catlover.com> writes:

> >     if(/<Member number=".*" status=".*">/) {
> 
> /<Member number=".*?" status=".*?">/
> 
> Without the first question mark, $1 will contain everything till the
> last quotation mark.

Well... it will *try* to -- and then it will be unable to match the
rest of the expression so it will have to backtrack until the match
succeeds.  I'm not saying that you shouldn't include the question
marks, but they aren't strictly required, and I did say that the regex
was likely to permissive.

Remember, even a greedy quantifier has to yield to a successful match.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 17 Jan 2001 17:53:13 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Syntax -  Still need HELP
Message-Id: <m3lms9viqe.fsf@dhcp11-177.support.tivoli.com>

I'm afraid it looks like we're going to have to see more of the code
to figure out what the problem is.  If you comment out the problem
lines, the error will likely move to a different line.  Sometimes this
strategy can help you find the real problem.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 17 Jan 2001 23:31:31 GMT
From: dha@panix2.panix.com (David H. Adler)
Subject: Re: What do you call the => operator?
Message-Id: <slrn96caqj.t3a.dha@panix2.panix.com>

On Wed, 17 Jan 2001 19:54:56 +0000, Lee Webb
<lwebbee@britcomtele.comnotreal> wrote:

>I'm the original poster of the message that Tad "didn't like". I didn't 
>like his reply so I EMAILED him about it and explained why I posted what I 
>did.
>
>Granted, I hated the message that he sent, but that still doesn't give me a 
>right to slag him off, *especially* publically on the newsgroup.
>
>(I'm not sure if this message is hypocritical: I'm *not* slagging you off 
>here Matt either, but then again I could have sent this to you personally. 
>Hmmm...)

Depends on what you think "slagging off" is.  Your message was a
polite disagreement, while the message you responded to was unpleasant
and contained a notable amount of personal attack (and obvious lack of
knowledge of this newsgroup).

I don't consider a polite disagreement to be "slagging off".

YMMV.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
she's a lovetarian especially in the form of puppies
      - Jellyfish, Sebrina, Paste and Plato


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 85
*************************************


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