[23121] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5342 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 10 21:05:42 2003

Date: Sun, 10 Aug 2003 18:05:08 -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           Sun, 10 Aug 2003     Volume: 10 Number: 5342

Today's topics:
    Re: A simple doubt :-/ (Sam Holden)
    Re: A simple doubt :-/ <pkent77tea@yahoo.com.tea>
    Re: connecting to a database (with no web server) <jwillmore@cyberia.com>
    Re: connecting to a database (with no web server) <member32241@dbforums.com>
    Re: connecting to a database (with no web server) <noreply@gunnar.cc>
    Re: connecting to a database (with no web server) <member32241@dbforums.com>
    Re: connecting to a database (with no web server) <noreply@gunnar.cc>
    Re: connecting to a database (with no web server) <NOSPAM@bigpond.com>
    Re: connecting to a database (with no web server) <r_reidy@comcast.net>
        Fetching remote password protected pages (Tom Cook)
    Re: Fetching remote password protected pages <NOSPAM@bigpond.com>
    Re: Location problem <REMOVEsdnCAPS@comcast.net>
    Re: Location problem <flavell@mail.cern.ch>
    Re: Perl Math Syntax (remove the obvious)
        Regex Head Scratcher <mooseshoes@gmx.net>
    Re: Regex Head Scratcher <mooseshoes@gmx.net>
    Re: Regex Head Scratcher <krahnj@acm.org>
    Re: Regex Head Scratcher (Sam Holden)
    Re: Regex Head Scratcher (Sam Holden)
    Re: Regex Head Scratcher <mooseshoes@gmx.net>
    Re: Regex Head Scratcher (Sam Holden)
    Re: Script displays in dos window, not browser <NOSPAM@bigpond.com>
    Re: Script displays in dos window, not browser <joe@burnettworks.com>
    Re: Script displays in dos window, not browser <NOSPAM@bigpond.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Aug 2003 18:20:10 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: A simple doubt :-/
Message-Id: <slrnbjd36p.m0g.sholden@flexal.cs.usyd.edu.au>

On Fri, 8 Aug 2003 19:20:49 +0000 (UTC),
	Louis Erickson <wwonko@rdwarf.com> wrote:
> 
> I haven't found a way to use mod_perl that wasn't horribly difficult.
> This may be my missing something obvious, and if it is, I'd very much
> love to be hit with the clue stick.  None of the tutorials or documentation
> I've seen talks about how to take a functioning, cleanly written CGI
> program and make it run correctly under mod_perl.

http://perl.apache.org/docs/1.0/guide/porting.html

Covers most of the issues with moving from CGI to mod_perl. Though
you've probably read it.


-- 
Sam Holden



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

Date: Sun, 10 Aug 2003 23:55:20 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: A simple doubt :-/
Message-Id: <pkent77tea-C1BDAB.23551610082003@usenet.force9.net>

In article <slrnbjd36p.m0g.sholden@flexal.cs.usyd.edu.au>,
 sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote:

> On Fri, 8 Aug 2003 19:20:49 +0000 (UTC),
> 	Louis Erickson <wwonko@rdwarf.com> wrote:
> > 
> > I haven't found a way to use mod_perl that wasn't horribly difficult.
> > This may be my missing something obvious, and if it is, I'd very much
> > love to be hit with the clue stick.  None of the tutorials or documentation
> > I've seen talks about how to take a functioning, cleanly written CGI
> > program and make it run correctly under mod_perl.

IME if your program really is a cleanly written CGI it runs Just Fine 
under mod_perl. But if that's not your experience I fully second the 
recommendation of:

> http://perl.apache.org/docs/1.0/guide/porting.html

My hint would be to completely ignore handlers and Apache::* stuff until 
you're au fait with the environment... and even then only if you really 
want to or need to. I've very very rarely had to do anything other that 
required mod_perl handlers, for example. At my place we write stuff so 
that it runs as a CGI or under mod_perl just the same, with no changes 
(of course running it under mod_perl is generally faster and more 
efficient and so on)

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Sun, 10 Aug 2003 18:26:54 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: connecting to a database (with no web server)
Message-Id: <20030810142611.7d452476.jwillmore@cyberia.com>

> Is this practicable?
> 
> I observed that in the connect function we must specified the host.
> What if there is not web server?

host, in the DBI 'connect' method, refers to the host where the
database resides.  If you are using a modern RDBMS (ie MySQL,
PostgreSQL, Sybase, Oracle, etc), this refers to where the database is
'living'.  So, for example, you are trying to connect to a MySQL
database on the same machine as the script, the host is probably
'localhost'.

Please read the documentation more carefully.  You may find what you
need there.

HTH

Jim


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

Date: Sun, 10 Aug 2003 18:42:57 +0000
From: dominant <member32241@dbforums.com>
Subject: Re: connecting to a database (with no web server)
Message-Id: <3222719.1060540977@dbforums.com>



#!/usr/bin/perl
#
# Cannonical Perl DBI connection to Mysql.
##############################################################################


use DBI;

$db = "username";	# your username (= login name  = account name )
$host = "127.0.0.1";    # = "localhost", the server your are on.
$user = $db;		# your Database name is the same as your account name.
$pwd = "mypassw";	# Your account password


# connect to the database.


$dbh = DBI->connect( "DBI:mysql:$db:$host", $user, $pwd)
		or die "Connecting : $DBI::errstr\n ";

$sql = "SELECT * FROM blah_table";


# executing the SQL statement.


$sth = $dbh->prepare($sql) or die "preparing: ",$dbh->errstr;
$sth->execute or die "executing: ", $dbh->errstr;

print "content-type: text/html\n\n";


# one of the functions to retrieve data from the table results 
# check perldoc DBI for more methods.


while ($row = $sth->fetchrow_hashref)		
{
	print $row->{'some_field_name'},'<BR>';	
}

That's it what i mean, the variable $host.

If mysql runs under no web server what is going on then?

Could post the ideal code for any database connection (and
particularly Oracle)

Thanks in advance!

--
Posted via http://dbforums.com


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

Date: Sun, 10 Aug 2003 21:56:54 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: connecting to a database (with no web server)
Message-Id: <bh683i$uub4t$1@ID-184292.news.uni-berlin.de>

dominant wrote:
> 
> use DBI;
> 
> $host = "127.0.0.1";    # = "localhost", the server your are on.
> 
> That's it what i mean, the variable $host.

I see the variable $host, but what is the rest? A script that somebody 
wrote and that you are trying to install, or just some sample code 
related to the use of the DBI module? Whatever it is, did you ask the 
one who wrote it?

Anyway, you could try to just keep '127.0.0.1' as the value of $host, 
or you could try to change it to 'localhost'.

I couldn't help noticing that 'somebody' suggested that you "check 
perldoc DBI". Have you done so?

     http://search.cpan.org/author/TIMB/DBI-1.37/DBI.pm

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



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

Date: Sun, 10 Aug 2003 20:45:13 +0000
From: dominant <member32241@dbforums.com>
Subject: Re: connecting to a database (with no web server)
Message-Id: <3222917.1060548313@dbforums.com>


The script comes from http://www.he.net/info/mysql/perldbi.html

I just wanted to see how the DBI works for the Mysql.

But now i want to conncet with the Oracle Server. The problem is that is
on another system(solaris) while the perl program which i want to create
is on a Windows system. In that case, what is the $host variable i
should define?

--
Posted via http://dbforums.com


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

Date: Sun, 10 Aug 2003 23:55:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: connecting to a database (with no web server)
Message-Id: <bh6f1q$ur7g6$1@ID-184292.news.uni-berlin.de>

dominant wrote:
> I just wanted to see how the DBI works for the Mysql.
> 
> But now i want to conncet with the Oracle Server. The problem is
> that is on another system(solaris) while the perl program which i
> want to create is on a Windows system. In that case, what is the
> $host variable i should define?

Dear "dominant",

This group is for discussing the Perl language:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

Since your question(s) are not about Perl problems, this is not the
right place.

When reading that last question, I believe that there are quite a few
pieces that you need to get in place, and that the value of that $host
variable is your least problem...

Guess you should buy a book, and start learning some basics about and
the difference between things like
- a (SQL) database
- a server
- an operating system

Good luck!

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



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

Date: Mon, 11 Aug 2003 08:50:59 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: connecting to a database (with no web server)
Message-Id: <bh6i8h$ur15b$1@ID-202028.news.uni-berlin.de>

"dominant" <member32241@dbforums.com> wrote in message
news:3222917.1060548313@dbforums.com...
>
> The script comes from http://www.he.net/info/mysql/perldbi.html
>
> I just wanted to see how the DBI works for the Mysql.
>
> But now i want to conncet with the Oracle Server. The problem is that is
> on another system(solaris) while the perl program which i want to create
> is on a Windows system. In that case, what is the $host variable i
> should define?
>
> --
> Posted via http://dbforums.com

If the host is called 'xyz.com', you set the host to 'xyz.com'.
The host must be visible to you via your network as an IP address or domain
name. You might need to open a port on the host to let your query through.

gtoomey






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

Date: Sun, 10 Aug 2003 18:20:03 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: connecting to a database (with no web server)
Message-Id: <3F36E133.3090208@comcast.net>

$host is specific (I think) to mySQL.  To be sure, look at the 
DBD::mysql docs.  For Oracle, you need to:

1.  Read the DBI docs (perldoc DBI).
2.  Read the DBD::Oracle docs (perldoc DBD::Oracle)

You may also want to familiarize yourself with Oracle networking (Net8) 
and remote access (assuming you are accessing an instance that is not on 
your windows machine).


-- 
Ron Reidy
Oracle DBA

dominant wrote:
> The script comes from http://www.he.net/info/mysql/perldbi.html
> 
> I just wanted to see how the DBI works for the Mysql.
> 
> But now i want to conncet with the Oracle Server. The problem is that is
> on another system(solaris) while the perl program which i want to create
> is on a Windows system. In that case, what is the $host variable i
> should define?
> 
> --
> Posted via http://dbforums.com




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

Date: 10 Aug 2003 16:23:07 -0700
From: tcook@tomservo.net (Tom Cook)
Subject: Fetching remote password protected pages
Message-Id: <1439a83a.0308101523.4dc28149@posting.google.com>

I'm trying to put together a script that will allow a user to:

a) log in to the script
b) once logged in, be presented with links to other sites that all
require regular HTTP authentication.
c) have the user click on the links and automagically go to the other
sites and be logged in there BUT I don't want the url or status bar to
look like "http://user:pass@website.com" because that's pretty
insecure.

I've already got the part about logging in set up and working, but how
can I construct the site so that the user is either (a) already logged
when they click on the link (like logging the user in before they even
see the link) or (b) having the credentials sent to the server in some
other way through the link.

Thanks for any answer!


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

Date: Mon, 11 Aug 2003 09:37:12 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: Fetching remote password protected pages
Message-Id: <bh6kv5$te4pi$1@ID-202028.news.uni-berlin.de>

"Tom Cook" <tcook@tomservo.net> wrote in message
news:1439a83a.0308101523.4dc28149@posting.google.com...

Apart from the fact that your have no Perl question ....

> I'm trying to put together a script that will allow a user to:
>
> a) log in to the script
> b) once logged in, be presented with links to other sites that all
> require regular HTTP authentication.
> c) have the user click on the links and automagically go to the other
> sites and be logged in there BUT I don't want the url or status bar to
> look like "http://user:pass@website.com" because that's pretty
> insecure.

The userid/password will be passed unencrypted if you use http and "basic
authentication". You have to live with it. If the web sites support https
use that.

>
> I've already got the part about logging in set up and working, but how
> can I construct the site so that the user is either (a) already logged
> when they click on the link (like logging the user in before they even
> see the link)
The only way to supply userid/password to a URL without the password popup
is the method you described.

or (b) having the credentials sent to the server in some
> other way through the link.
Perhaps use cookies? But you need contol of the web server at the other end.

gtoomey




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

Date: Sun, 10 Aug 2003 14:21:16 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Location problem
Message-Id: <Xns93D39BFE330DFsdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Alan J. Flavell" <flavell@mail.cern.ch> wrote in
news:Pine.LNX.4.53.0308101505480.3463@lxplus010.cern.ch: 

> On Sun, Aug 10, Eric J. Roode inscribed on the eternal scroll:
> 
>> "For some reason"...?   I think you need to go read up on how HTTP
>> headers work...
> 
> From the context, I understood the question to be about a CGI
> response, rather than a raw HTTP transaction response.
> 
> They're very similar, of course, by design; but there are subtle
> differences, so I'd have to recommend keeping the concepts distinct on
> one's mind.
> 
> Of course, this has nothing specifically to do with Perl.
> 
> But as perlport points out, the correct portable terminator for
> interworking sockets (and this goes for HTTP) would be \015\012 (i.e
> CRLF)  written in binary mode.
> 
> For CGI, however, where the process is communicating with the web
> server (httpd) on the _same_ platform, the platform-specific newline
> representation, i.e \n , is considered appropriate.  And that's what
> we saw being used in this presumed-CGI context, so that detail was OK
> (the problem lay elsewhere, as I said before).
> 
> So that at least manages to drag _some_ Perl relevance into the
> thread, even if this particular issue doesn't answer the questioner's
> problem ;-)

CRLF vs LF is not the OP's problem.

The OP wrote:

# For some reason in this sendmail routine, if I position
# this line after a particular line in the sendmail rountine, print
# "Content-type: text/html\n\n";  it causes the redirect to print out as
# html on the screen only...

where "this line" means the "Location: http://..." line.

A CGI program's output consists of HTTP headers followed by content.  The 
headers are separated from the content by a pair of newlines (a pair of 
CRLF pairs, strictly speaking).  The OP clearly output a Content-type 
HTTP header, followed by a pair of newlines which ends the header set.  
No wonder the "Location" header was displayed on the browser screen as 
content instead of being used by the server or browser for redirection.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzaa42PeouIeTNHoEQKxkACgrEbcGns974PdOY47kvUF0OCkXVsAoKqz
RhIGVMiZuXAa8IEsJGczGdvv
=Q4GU
-----END PGP SIGNATURE-----


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

Date: Sun, 10 Aug 2003 23:44:47 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Location problem
Message-Id: <Pine.LNX.4.53.0308102325020.27560@lxplus078.cern.ch>

On Sun, Aug 10, Eric J. Roode inscribed on the eternal scroll:

[..comprehensive quote now snipped..]

> CRLF vs LF is not the OP's problem.

As I had said in my followup earlier in the thread, indeed.

> A CGI program's output consists of HTTP headers followed by content.

Excuse me, but as I already said: a CGI program's output consists of
a proper CGI response:

> >They're very similar, of course, by design; but there are subtle
> >differences, so I'd have to recommend keeping the concepts distinct

> The
[CGI]
> headers are separated from the content by a pair of newlines

Yes

> (a pair of CRLF pairs, strictly speaking).

No.  See the CGI specification.  The clue was in my posting which -
for whatever reason - you are contradicting.

>  The OP clearly output a Content-type HTTP header,

The posting had said:

||  Content-type: text/html\n\n

(it was a *CGI* header, and it used the appropriate "\n" newlines, as
I had pointed out but you then contradicted.)

> followed by a pair of newlines which ends the header set.

Indeed.  I thought we'd all be able to agree about that, and that it
wasn't a Perl problem.  That's why two separate postings redirected
the questioner to the CGI authoring group, along with a brief note of
their problem.

> No wonder the "Location" header was displayed on the browser screen

Quite.  I felt I had already dealt with that, and in my later f'up was
only dealing with a detail of your posting on the thread.

best regards


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

Date: Sun, 10 Aug 2003 20:24:19 GMT
From: "--Rick" <no_trick@my-de(remove the obvious)ja.com>
Subject: Re: Perl Math Syntax
Message-Id: <TRxZa.95295$0v4.6556179@bgtnsc04-news.ops.worldnet.att.net>


"John W. Krahn" <krahnj@acm.org> wrote in message
news:3F32B43C.D47B69B8@acm.org...
| --Rick wrote:
| >
| > "John W. Krahn" <krahnj@acm.org> wrote in message
| > news:3F31B5D3.E0C7FE40@acm.org...
| > |
| > | Sorry, I forgot to backwack the veritcal bars.  :-)
| > |
| > | #!/usr/bin/perl -p
| > |
| > | BEGIN { ( $^I, @ARGV ) = ( '', 'opened.txt' ) }
| > | s/\|(\d+)\|/|@{[$1+1]}|/
| >
| > OK, I'm not so sleepy this time.
| >
| > I did figure out that the pipe characters needed to be escaped.
What
| > I was really meaning to ask (and I asked poorly) was this.  I
could
| > not understand the idiom you used to get addition into the
replacement
| > string nor could I make it work (surprise!).  What I got instead
was a
| > printed addition problem.  Could you explain it or point me to the
| > right place in the documentation?
|
| Well, it works fine for me.  :-)
|
| $ perl -le'
| $_ = "1234|12|5678";
| print;
| s/\|(\d+)\|/|@{[$1+1]}|/;
| print;
| '
| 1234|12|5678
| 1234|13|5678
|
|
| The "@{[  ]}" idiom is described in the FAQ:
|
| perldoc -q "How do I expand function calls in a string"
|

Egad!  I asked a FAQ!  I was blindly looking for expanding functions
in regexen and it didn't occur to me that it was just a string.
Still, I learned something useful.  Thanks for pointing me to the
answer.

And, yes, on my second session it did work for me, although I had to
put an extension for in-place edit.

--Rick {apparently an eternal beginner =0)}




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

Date: 10 Aug 2003 21:53:26 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Regex Head Scratcher
Message-Id: <bh6esm$bj5@dispatch.concentric.net>

All:

I've run into a dark alley with a regex and could use some assistance.

I have a list of keywords as keys in a hash (eg. %keywords) and I am looking
at each key to see if it can be matched in a string.

For example, let's say the current $keyword is "bush" and the $phrase is:

"George Bush arrived in San Francisco today from a trip to Russia."

Quite simply, the expression $phrase =~ /$keyword/is; would be a positive
match on "Bush".  If $keyword becomes "U.S." the result not too
surprisingly become positive as well ("us" in Russia).  Well, this is
undesirable so I change the expression to $phrase =~ /\Q$keyword/is; and
now there is no longer a match on "U.S." which is the desired result.

This is still insufficient, however, because if the $keyword becomes "Cisco"
there will be a positive match on "Francisco".  Therefore, I'll make some
accommodation for leading and trailing characters in the expression in
order to isolate the keywords, thus:

$phrase =~ /(?:\s|'|"|\()$keyword(?:,|'|"|!|\.|\s|\))/is;

OK, so this works just fine but now I'm back to the "U.S." problem again and
I'd like to stick the \Q back in but clearly this will render the new parts
of the expression useless.

The question, therefore is how can I treat $keyword as quoted in this
context?

One thing I did try was to assign qq($keyword) to a new variable and search
on that variable, but this didn't seem to have an impact.

Thank you for your time and thoughts.

Moose



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

Date: 10 Aug 2003 22:05:12 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: Regex Head Scratcher
Message-Id: <bh6fio$bjb@dispatch.concentric.net>

Please use this as the expression in question in the previous post:

$phrase =~ /(?:\s|'|"|\()?$keyword(?:,|'|"|!|\.|\s|\))?/is;


mooseshoes wrote:

> All:
> 
> I've run into a dark alley with a regex and could use some assistance.
> 
> I have a list of keywords as keys in a hash (eg. %keywords) and I am
> looking at each key to see if it can be matched in a string.
> 
> For example, let's say the current $keyword is "bush" and the $phrase is:
> 
> "George Bush arrived in San Francisco today from a trip to Russia."
> 
> Quite simply, the expression $phrase =~ /$keyword/is; would be a positive
> match on "Bush".  If $keyword becomes "U.S." the result not too
> surprisingly become positive as well ("us" in Russia).  Well, this is
> undesirable so I change the expression to $phrase =~ /\Q$keyword/is; and
> now there is no longer a match on "U.S." which is the desired result.
> 
> This is still insufficient, however, because if the $keyword becomes
> "Cisco"
> there will be a positive match on "Francisco".  Therefore, I'll make some
> accommodation for leading and trailing characters in the expression in
> order to isolate the keywords, thus:
> 
> $phrase =~ /(?:\s|'|"|\()$keyword(?:,|'|"|!|\.|\s|\))/is;
> 
> OK, so this works just fine but now I'm back to the "U.S." problem again
> and I'd like to stick the \Q back in but clearly this will render the new
> parts of the expression useless.
> 
> The question, therefore is how can I treat $keyword as quoted in this
> context?
> 
> One thing I did try was to assign qq($keyword) to a new variable and
> search on that variable, but this didn't seem to have an impact.
> 
> Thank you for your time and thoughts.
> 
> Moose



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

Date: Sun, 10 Aug 2003 22:08:16 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Regex Head Scratcher
Message-Id: <3F36C24C.8B7662A9@acm.org>

mooseshoes wrote:
> 
> I've run into a dark alley with a regex and could use some assistance.
> 
> I have a list of keywords as keys in a hash (eg. %keywords) and I am looking
> at each key to see if it can be matched in a string.
> 
> For example, let's say the current $keyword is "bush" and the $phrase is:
> 
> "George Bush arrived in San Francisco today from a trip to Russia."
> 
> Quite simply, the expression $phrase =~ /$keyword/is; would be a positive
> match on "Bush".  If $keyword becomes "U.S." the result not too
> surprisingly become positive as well ("us" in Russia).  Well, this is
> undesirable so I change the expression to $phrase =~ /\Q$keyword/is; and
> now there is no longer a match on "U.S." which is the desired result.
> 
> This is still insufficient, however, because if the $keyword becomes "Cisco"
> there will be a positive match on "Francisco".  Therefore, I'll make some
> accommodation for leading and trailing characters in the expression in
> order to isolate the keywords, thus:
> 
> $phrase =~ /(?:\s|'|"|\()$keyword(?:,|'|"|!|\.|\s|\))/is;

You probably want to use the \b word boundary zero width assertion.

$phrase =~ /\b\Q$keyword\E\b/is;


John
-- 
use Perl;
program
fulfillment


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

Date: 10 Aug 2003 22:19:52 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Regex Head Scratcher
Message-Id: <slrnbjdh87.ohm.sholden@flexal.cs.usyd.edu.au>

On 10 Aug 2003 21:53:26 GMT, mooseshoes <mooseshoes@gmx.net> wrote:
> All:
> 
> I've run into a dark alley with a regex and could use some assistance.
> 
> I have a list of keywords as keys in a hash (eg. %keywords) and I am looking
> at each key to see if it can be matched in a string.
> 
> For example, let's say the current $keyword is "bush" and the $phrase is:
> 
> "George Bush arrived in San Francisco today from a trip to Russia."
> 
> Quite simply, the expression $phrase =~ /$keyword/is; would be a positive
> match on "Bush".  If $keyword becomes "U.S." the result not too
> surprisingly become positive as well ("us" in Russia).  Well, this is
> undesirable so I change the expression to $phrase =~ /\Q$keyword/is; and
> now there is no longer a match on "U.S." which is the desired result.

Small nitpick it "U.S." does not match the "us" in Russia, it matches
the "ussi" in Russia (if it was going to match "us" it'd grab the one
in Bush :).

> 
> This is still insufficient, however, because if the $keyword becomes "Cisco"
> there will be a positive match on "Francisco".  Therefore, I'll make some
> accommodation for leading and trailing characters in the expression in
> order to isolate the keywords, thus:
> 
> $phrase =~ /(?:\s|'|"|\()$keyword(?:,|'|"|!|\.|\s|\))/is;

That isn't going to work, take for example your $phrase above and
the keyword "george".

Use \b, it in all likelyhood does what you actually want.

See "perldoc perlre" for details on \b.

Also, the /s modifier is useless, since all it does is change "." to 
match all characters (instead of all characters bar "\n"). Since you 
don't have any (unescaped) "."s in your regex /s just serves to confuse
the reader of the regex (who will look for a dot).

Again, "perldoc perlre" for details on /s.

> 
> OK, so this works just fine but now I'm back to the "U.S." problem again and
> I'd like to stick the \Q back in but clearly this will render the new parts
> of the expression useless.

There is \E as well as \Q.

See "perldoc perlre" again, for details.

> The question, therefore is how can I treat $keyword as quoted in this
> context?

$phrase=~/\b\Q$keyword\E\b/i;

You could also use:

$keyword = quotemeta $keyword;

$phrase=~/\b$keyword\b/i;

Though you might want to use a different name if you need the original
later.


> One thing I did try was to assign qq($keyword) to a new variable and search
> on that variable, but this didn't seem to have an impact.

Why would it? 

"$foo = qq($bar)" is the same as "$foo = $bar" if $bar is a string already.

Programming by guess is not efficient...

-- 
Sam Holden



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

Date: 10 Aug 2003 22:23:36 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Regex Head Scratcher
Message-Id: <slrnbjdhf8.ohm.sholden@flexal.cs.usyd.edu.au>

On 10 Aug 2003 22:05:12 GMT, mooseshoes <mooseshoes@gmx.net> wrote:
> Please use this as the expression in question in the previous post:
> 
> $phrase =~ /(?:\s|'|"|\()?$keyword(?:,|'|"|!|\.|\s|\))?/is;

That matches exactly the same set of strings as

$phrase =~ /$keyword/i;

does. Putting element which can match the empty string at either
end of regex will not change the strings it matches (it may cause it
to capture different parts of the string, but you aren't doing
any capturing).

[snip "previous post"]

-- 
Sam Holden



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

Date: 11 Aug 2003 00:14:20 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: Regex Head Scratcher
Message-Id: <bh6n4s$bnq@dispatch.concentric.net>

Sam (and John if you're listening):

Thank you for your helpful remarks.

You both came up with the same solution (great minds think alike?) and I now
fully understand both the errors of my ways and why the proposed solution
is the best approach.  Despite the fact that perlretut and Wall's bible go
to bed with me each night, discovering perlre will be a very helpful
resource as perlretut is light on both \b and \E.

Regarding /s, I didn't mention earlier that the phrases were actually
sub-phrases of HTML pages converted to text and having had trouble with
line breaks in previous experiences with these strings I had left in the
/s, but potentially I can remove it at this point.

And yes, I am occasionally guilty of what I call programming "flailing"
which is a bad practice of inserting code with only a vague notion of what
the result may be.  I think I can attribute this to spending many years in
the marketing departments of large companies.  ;)  I generally do catch
myself, however, as I do prefer to know what is going on.

Cheers,

Moose




Sam Holden wrote:

> On 10 Aug 2003 21:53:26 GMT, mooseshoes <mooseshoes@gmx.net> wrote:
>> All:
>> 
>> I've run into a dark alley with a regex and could use some assistance.
>> 
>> I have a list of keywords as keys in a hash (eg. %keywords) and I am
>> looking at each key to see if it can be matched in a string.
>> 
>> For example, let's say the current $keyword is "bush" and the $phrase is:
>> 
>> "George Bush arrived in San Francisco today from a trip to Russia."
>> 
>> Quite simply, the expression $phrase =~ /$keyword/is; would be a positive
>> match on "Bush".  If $keyword becomes "U.S." the result not too
>> surprisingly become positive as well ("us" in Russia).  Well, this is
>> undesirable so I change the expression to $phrase =~ /\Q$keyword/is; and
>> now there is no longer a match on "U.S." which is the desired result.
> 
> Small nitpick it "U.S." does not match the "us" in Russia, it matches
> the "ussi" in Russia (if it was going to match "us" it'd grab the one
> in Bush :).
> 
>> 
>> This is still insufficient, however, because if the $keyword becomes
>> "Cisco"
>> there will be a positive match on "Francisco".  Therefore, I'll make some
>> accommodation for leading and trailing characters in the expression in
>> order to isolate the keywords, thus:
>> 
>> $phrase =~ /(?:\s|'|"|\()$keyword(?:,|'|"|!|\.|\s|\))/is;
> 
> That isn't going to work, take for example your $phrase above and
> the keyword "george".
> 
> Use \b, it in all likelyhood does what you actually want.
> 
> See "perldoc perlre" for details on \b.
> 
> Also, the /s modifier is useless, since all it does is change "." to
> match all characters (instead of all characters bar "\n"). Since you
> don't have any (unescaped) "."s in your regex /s just serves to confuse
> the reader of the regex (who will look for a dot).
> 
> Again, "perldoc perlre" for details on /s.
> 
>> 
>> OK, so this works just fine but now I'm back to the "U.S." problem again
>> and I'd like to stick the \Q back in but clearly this will render the new
>> parts of the expression useless.
> 
> There is \E as well as \Q.
> 
> See "perldoc perlre" again, for details.
> 
>> The question, therefore is how can I treat $keyword as quoted in this
>> context?
> 
> $phrase=~/\b\Q$keyword\E\b/i;
> 
> You could also use:
> 
> $keyword = quotemeta $keyword;
> 
> $phrase=~/\b$keyword\b/i;
> 
> Though you might want to use a different name if you need the original
> later.
> 
> 
>> One thing I did try was to assign qq($keyword) to a new variable and
>> search on that variable, but this didn't seem to have an impact.
> 
> Why would it?
> 
> "$foo = qq($bar)" is the same as "$foo = $bar" if $bar is a string
> already.
> 
> Programming by guess is not efficient...
> 



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

Date: 11 Aug 2003 01:03:05 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Regex Head Scratcher
Message-Id: <slrnbjdqq9.fnv.sholden@flexal.cs.usyd.edu.au>

On 11 Aug 2003 00:14:20 GMT, mooseshoes <mooseshoes@gmx.net> wrote:
> Sam (and John if you're listening):
> 
> Thank you for your helpful remarks.
> 
> You both came up with the same solution (great minds think alike?) and I now
> fully understand both the errors of my ways and why the proposed solution
> is the best approach.  Despite the fact that perlretut and Wall's bible go
> to bed with me each night, discovering perlre will be a very helpful
> resource as perlretut is light on both \b and \E.

More the normal way of performing such a match than great minds...

Of course if you haven't come across \b and \E, you aren't going to
know the "normal" way.

>
> And yes, I am occasionally guilty of what I call programming "flailing"
> which is a bad practice of inserting code with only a vague notion of what
> the result may be.  I think I can attribute this to spending many years in
> the marketing departments of large companies.  ;)  I generally do catch
> myself, however, as I do prefer to know what is going on.

I think everyone "flails" at times, though with perl the documentation is
of an amazingly high quality and hence there is little need to. Trial and
error can on occassions be a useful learning method - as long as you 
take the time to learn why the things which failed failed, and why the
things which worked worked.

[snip quote of entire article]

You really shouldn't do that. Many of the most experienced and helpful
people here don't like it, and ignore posts from people who keep doing
it. Taking the time to trim the quoted text to only what is necessary
to give context to the reader will make your life easier later.

See the Posting Guidelines which are posted here frequently or on the web
at http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html for
some other useful tips to making the most out of this newsgroup.

-- 
Sam Holden


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

Date: Mon, 11 Aug 2003 09:11:47 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: Script displays in dos window, not browser
Message-Id: <bh6jfh$v5p91$1@ID-202028.news.uni-berlin.de>

"Joe Burnett" <joe@burnettworks.com> wrote in message
news:KluZa.113785$Ho3.14438@sccrnsc03...
> Hello,
>
> I am trying to run a trivial perl script, but the results either get
> displayed in a dos window,
> or the source code gets displayed in a browser. The former happens when I
> open the script
> in IE with a pl extension. The latter happens if I open the script with a
> cgi extension. Both
> scripts reside in "C:\Program Files\Apache Group\Apache2\cgi-bin".
> Obviously, I have an
> apache server (the service is started, as well as two apache.exe
processes).
> I have ActiveState
> perl installed. Here is the script:
>
 ...
> I have been looking in the news groups for two days to no avail.
>
> Thanks,
>
> Joe

Looking for two days? Where? If you spent 2 days reading the Apache
documentation you should know it by heart.


You will probably need the following in your Apache config file:

AddHandler cgi-script cgi pl
# tells Apache that files ending in cgi or pl are to be run as cgi

<Directory /home>
        Options +ExecCGI
</Directory>
# allows cgi to be run in /home and subdirectories
# change /home to the root directory of your web site


gtoomey




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

Date: Sun, 10 Aug 2003 23:28:52 GMT
From: "Joe Burnett" <joe@burnettworks.com>
Subject: Re: Script displays in dos window, not browser
Message-Id: <UyAZa.116059$uu5.17089@sccrnsc04>

Gregory, thanks for the reply.
> Looking for two days? Where? If you spent 2 days reading the Apache
> documentation you should know it by heart.
Well, off and on for two days. Even if I did know the Apache stuff by heart,
I don't think it would help. I implemented the changes you suggested and the
behavio(u)r did not change. Still get either a DOS window (.pl) or the
source
code displayed in IE (.cgi).

Do you have any other suggestions? Is the fact that I have a Windows XP Pro
as my server, but have specified DHCP to get the IP address (which by the
way
matches the address in my httpd.conf) creating the problem?

Thanks again,

Joe

"Gregory Toomey" <NOSPAM@bigpond.com> wrote in message
news:bh6jfh$v5p91$1@ID-202028.news.uni-berlin.de...
> "Joe Burnett" <joe@burnettworks.com> wrote in message
> news:KluZa.113785$Ho3.14438@sccrnsc03...
> > Hello,
> >
> > I am trying to run a trivial perl script, but the results either get
> > displayed in a dos window,
> > or the source code gets displayed in a browser. The former happens when
I
> > open the script
> > in IE with a pl extension. The latter happens if I open the script with
a
> > cgi extension. Both
> > scripts reside in "C:\Program Files\Apache Group\Apache2\cgi-bin".
> > Obviously, I have an
> > apache server (the service is started, as well as two apache.exe
> processes).
> > I have ActiveState
> > perl installed. Here is the script:
> >
> ...
> > I have been looking in the news groups for two days to no avail.
> >
> > Thanks,
> >
> > Joe
>
> Looking for two days? Where? If you spent 2 days reading the Apache
> documentation you should know it by heart.
>
>
> You will probably need the following in your Apache config file:
>
> AddHandler cgi-script cgi pl
> # tells Apache that files ending in cgi or pl are to be run as cgi
>
> <Directory /home>
>         Options +ExecCGI
> </Directory>
> # allows cgi to be run in /home and subdirectories
> # change /home to the root directory of your web site
>
>
> gtoomey
>
>




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

Date: Mon, 11 Aug 2003 09:41:29 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: Script displays in dos window, not browser
Message-Id: <bh6l77$ug0ra$1@ID-202028.news.uni-berlin.de>

"Joe Burnett" <joe@burnettworks.com> wrote in message
news:UyAZa.116059$uu5.17089@sccrnsc04...
> Gregory, thanks for the reply.
> > Looking for two days? Where? If you spent 2 days reading the Apache
> > documentation you should know it by heart.
> Well, off and on for two days. Even if I did know the Apache stuff by
heart,
> I don't think it would help. I implemented the changes you suggested and
the
> behavio(u)r did not change. Still get either a DOS window (.pl) or the
> source
> code displayed in IE (.cgi).
>
> Do you have any other suggestions? Is the fact that I have a Windows XP
Pro
> as my server, but have specified DHCP to get the IP address (which by the
> way
> matches the address in my httpd.conf) creating the problem?
>
> Thanks again,
>
> Joe
>

Step number 1 to to make sure you can access regular html.
eg http://www.yoursite.com/mypage.html
If you can't even do that then you need to sort out DNS issues.

When you have that working you can try something like
http://www.yoursite.com/cgi/bin/script.cgi


gtoomey






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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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.  

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


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