[19562] in Perl-Users-Digest
Perl-Users Digest, Issue: 1757 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 16 18:10:30 2001
Date: Sun, 16 Sep 2001 15:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000678212-v10-i1757@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 16 Sep 2001 Volume: 10 Number: 1757
Today's topics:
Pattern Match Arguments in Variable <stephan@buckmaster.ca>
Re: Pattern Match Arguments in Variable (Mark Jason Dominus)
Re: Pattern Match Arguments in Variable (Randal L. Schwartz)
Re: Pattern Match Arguments in Variable <bart.lateur@skynet.be>
Re: Reading cookies from a different path (Mark Jason Dominus)
s/// modifies @_ ? <pilsl_@goldfisch.at>
Re: s/// modifies @_ ? <bwalton@rochester.rr.com>
Re: s/// modifies @_ ? <pilsl_@goldfisch.at>
Re: Similar file finder (Mark Jason Dominus)
Re: Similar file finder <sun_tong@users.sourceforge.net>
Unresolved symbol dynamically loading an xsub (Remko Noteboom)
vbScript to Perl? <wgrigg@draper.com>
Re: vbScript to Perl? (Tim Hammerquist)
Re: vbScript to Perl? <bwalton@rochester.rr.com>
Re: XML::XSLT - 'Can't call method "getNodeValue" on an (Jay McGavren)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 16 Sep 2001 10:33:10 -0400
From: "Stephan Wehner" <stephan@buckmaster.ca>
Subject: Pattern Match Arguments in Variable
Message-Id: <pan.2001.09.16.10.33.10.4.6379@buckmaster.ca>
I thought Perl would allow me to use a variable to specify regular
expression arguments. But it doesn't. How come?? Will this be added?
See example program below.
-- Stephan
#!/usr/bin/perl
# this part is fine and prints 'n' on the terminal.
"test string" =~ /(N)/i; # can we use a variable instead of i
print "$1\n";
# but this part doesn't work
$matcher = 'i';
"test string" =~ /(N)/$matcher; # this does not compile
print "$1\n";
~
------------------------------
Date: Sun, 16 Sep 2001 17:42:42 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Pattern Match Arguments in Variable
Message-Id: <3ba4e492.324e$3e7@news.op.net>
In article <pan.2001.09.16.10.33.10.4.6379@buckmaster.ca>,
Stephan Wehner <stephan@buckmaster.ca> wrote:
>I thought Perl would allow me to use a variable to specify regular
>expression arguments.
Arguments, yes. Option flags, no.
> But it doesn't. How come??
Because it's difficult to implement. A regex with (say) /i is
compiled in a completely different way than a regex without it. For
example, there are all sorts of optimizations that are possible if
there is no /i, but which much be disabled if there was /i.
Perl would need to wait until run time to compile the regex, and
recompile it each time you wanted to do a match, depending on the
option flags.
There is already an easy way to get this behavior if that is what you
want:
$flag = "(?i)"; # or $flag = "";
"test string" =~ /$flag(S)/;
print "$1\n";
For more general cases, Perl's "eval" operator allows you to defer
compilation of code until run time:
$flag = "i"; # or $flag = "" or $flag = 'mxs' or whatever
$code = q{"test string" =~ /(S)/MYFLAGS};
$code =~ s/MYFLAGS/$flag/;
eval $code;
print "$1\n";
> Will this be added?
Extremely unlikely.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 16 Sep 2001 11:20:51 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Pattern Match Arguments in Variable
Message-Id: <m1pu8rngjg.fsf@halfdome.holdit.com>
>>>>> "Mark" == Mark Jason Dominus <mjd@plover.com> writes:
Mark> $flag = "(?i)"; # or $flag = "";
Mark> "test string" =~ /$flag(S)/;
Mark> print "$1\n";
While this is a great piece of code to demonstrate how the $flag works
here, it also triggers one of my pet peeves leading to faulty code:
the examination of the memory variables (like $1) without testing the
success of the regex match, which can lead to faulty or (worse)
insecure behavior. I'd write that as:
$flag = "(?i)"; # or $flag = "";
if ("test string" =~ /$flag(S)/) {
print "$1\n";
} else {
print "no match\n";
}
Otherwise, on a failed match, the $1 you're printing is the *previous*
match's $1. Probably unexpected by some who don't understand the
rule, that the memories are left unchanged on any *unsuccessful*
match.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sun, 16 Sep 2001 21:25:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Pattern Match Arguments in Variable
Message-Id: <n26aqtc5ckec7bmt3sgp7dt79on3rfmtpv@4ax.com>
Stephan Wehner wrote:
># this part is fine and prints 'n' on the terminal.
>"test string" =~ /(N)/i; # can we use a variable instead of i
>print "$1\n";
>
># but this part doesn't work
>$matcher = 'i';
>
>"test string" =~ /(N)/$matcher; # this does not compile
>print "$1\n";
>~
See what this prints.
print qr/(N)/i;
It might give you an idea for an alternative syntax.
--
Bart.
------------------------------
Date: Sun, 16 Sep 2001 17:30:25 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Reading cookies from a different path
Message-Id: <3ba4e1b0.31eb$7f@news.op.net>
In article <3ba3b9d2_6@goliath.newsgroups.com>,
Steve Quezadas <steveeq2@tripperjones.com> wrote:
>Does anyone know how to read cookies that exist on a different path?
You can't, because the browser doesn't send them.
The -path option only makes sense when you are *setting* a cookie in
the browser. It tells the browser to send the cookie back only when
requesting a document that begins with that path. For other
documents, the browser does not send the cookie.
>It never prints out the value of the cookie! Anyonw know if I am missing
>anything? or am I forced to run the program in directory /vegas?
If the cookie was set for /vegas, the browser will only send the
cookie back when it is requesting a document under /vegas.
If you want to do a little work, you don't have to move your entire
program to /vegas. You can use a trick. Suppose your program is in
/cgi-bin/realprogram. Make another program called
/vegas/showcookie.cgi. The code will look like this:
#!/usr/bin/perl
use CGI;
use URI::URL;
my $PROGRAM = '/cgi-bin/realprogram';
my $cookie = cookie(-name => 'vegas');
my $url = URI::URL->new($PROGRAM);
$url->scheme('http');
$url->host($ENV{SERVER_NAME});
$url->query_form('vegas cookie' => $cookie);
print CGI->redirect($url->abs);
exit;
All this does is get the vegas cookie and then redirect the browser
to the real program. It tells the browser to include the cookie in
the URL of the real program.
In the real program, you can do this:
my $query_args = CGI->new(CGI->query_string());
my $vegas_cookie = $query_args->param('vegas cookie');
unless (defined $vegas_cookie) {
my $url = URI::URL->new('/vegas/showcookie.cgi');
$url->scheme('http');
$url->host($ENV{SERVER_NAME});
$url->query_form('vegas cookie' => $cookie);
print CGI->redirect($url->abs);
exit;
}
# the rest of your program goes here...
The first thing your real program does is to look to see if someone
has given it the vegas cookie in the query string. If so, it proceeds
normally. otherwise, it redirects the browser to showcookie.cgi,
which gets the vegas cookie and calls the real program again, this
time with the vegas cookie in the query string.
Maybe that's not worth bothering with, but if you really don't want to
put the real program under /vegas, it's a way out.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sun, 16 Sep 2001 19:36:37 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: s/// modifies @_ ?
Message-Id: <3ba4e326$1@e-post.inode.at>
I recently found a bug in a script that I cant explain.
Inside a sub $_[1] changes its value during a simple s///-operator.
Only $_[1] and I couldnt reproduce the phenomen in a small script.
the affected part:
----------
print defined($_[1])?'yes':'no'; print "__<br>\n"; #temp
print join('-',map {defined($_)?$_:'undef'} ($_,$add,@_)),"<br>\n"; #temp
$add=~s/^.//;
print defined($_[1])?'yes':'no'; print "__<br>\n"; #temp
print join('-',map {defined($_)?$_:'undef'} ($_,$add,@_)),"<br>\n"; #temp
----------
gives the output:
yes__<br>
undef-$14-ARRAY(0x81650a4)-test-1-ARRAY(0x8167f94)-$14<br>
no__<br>
undef-14-ARRAY(0x81650a4)-undef-1-ARRAY(0x8167f94)-$14<br>
The meaning is only to delete the first char of $add. $_ is undefined and
@_ contains a lot of stuff.
As you can see the value $_[1] changes from 'test1' to undef and I dont
have any idea why ...
Imho it shouldnt do so.
same problem occures when I say:
$add=~s/^(\$|_|\.)//;
but not when I do a
$add=~s/a/b/;
which of course doesnt do what I want
I fixed the problem with
$add=substr($add,1,length($add));
but I have a bad feeling cause there is something I absolutely dont
understand ..
thnx,
peter
ps: perl 5.6.0 on linux
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Sun, 16 Sep 2001 20:56:04 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: s/// modifies @_ ?
Message-Id: <3BA51218.F2D17A1@rochester.rr.com>
peter pilsl wrote:
>
> I recently found a bug in a script that I cant explain.
> Inside a sub $_[1] changes its value during a simple s///-operator.
> Only $_[1] and I couldnt reproduce the phenomen in a small script.
>
> the affected part:
> ----------
> print defined($_[1])?'yes':'no'; print "__<br>\n"; #temp
> print join('-',map {defined($_)?$_:'undef'} ($_,$add,@_)),"<br>\n"; #temp
>
> $add=~s/^.//;
>
> print defined($_[1])?'yes':'no'; print "__<br>\n"; #temp
> print join('-',map {defined($_)?$_:'undef'} ($_,$add,@_)),"<br>\n"; #temp
> ----------
>
> gives the output:
> yes__<br>
> undef-$14-ARRAY(0x81650a4)-test-1-ARRAY(0x8167f94)-$14<br>
> no__<br>
> undef-14-ARRAY(0x81650a4)-undef-1-ARRAY(0x8167f94)-$14<br>
>
> The meaning is only to delete the first char of $add. $_ is undefined and
> @_ contains a lot of stuff.
> As you can see the value $_[1] changes from 'test1' to undef and I dont
> have any idea why ...
> Imho it shouldnt do so.
>
> same problem occures when I say:
> $add=~s/^(\$|_|\.)//;
>
> but not when I do a
> $add=~s/a/b/;
> which of course doesnt do what I want
>
> I fixed the problem with
> $add=substr($add,1,length($add));
>
> but I have a bad feeling cause there is something I absolutely dont
> understand ..
>
> thnx,
> peter
>
> ps: perl 5.6.0 on linux
>
> --
> peter pilsl
> pilsl_@goldfisch.at
> http://www.goldfisch.at
Peter, when I tried your code verbatim (with definitions of variables
added at the start to give the values shown in your output), it does not
generate any difference in $_[1]:
D:\junk>perl junk79.pl
yes__<br>
undef-$14-ARRAY(0x176f120)-test-1-ARRAY(0x1765570)-$14<br>
yes__<br>
undef-14-ARRAY(0x176f120)-test-1-ARRAY(0x1765570)-$14<br>
D:\junk>
You are aware that in a sub call, the entries in @_ are aliases, right?
Is there a chance the second argument to your sub is something that is
changed during the substitution, like one of Perl's special variables?
Hmmmm...using that theory, I am able to duplicate your results with:
$add='$14';
$a='xxxtestyyy';
$a=~/(test)/;
print "\$1 is $1\n";
test(['ar0','ar1'],$1,1,['b0','b1'],'$14');
sub test{
print defined($_[1])?'yes':'no'; print "__<br>\n"; #temp
print join('-',map {defined($_)?$_:'undef'} ($_,$add,@_)),"<br>\n";
$add=~s/^.//;
print defined($_[1])?'yes':'no'; print "__<br>\n"; #temp
print join('-',map {defined($_)?$_:'undef'} ($_,$add,@_)),"<br>\n";
}
D:\junk>perl junk79.pl
$1 is test
yes__<br>
undef-$14-ARRAY(0x176f120)-test-1-ARRAY(0x176f204)-$14<br>
no__<br>
undef-14-ARRAY(0x176f120)-undef-1-ARRAY(0x176f204)-$14<br>
D:\junk>perl -v
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 629 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 12:27:04 Aug 20 2001
--
Bob Walton
------------------------------
Date: Sun, 16 Sep 2001 23:20:50 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: s/// modifies @_ ?
Message-Id: <3ba517b3$1@e-post.inode.at>
Bob Walton wrote:
>
> You are aware that in a sub call, the entries in @_ are aliases, right?
> Is there a chance the second argument to your sub is something that is
> changed during the substitution, like one of Perl's special variables?
>
> Hmmmm...using that theory, I am able to duplicate your results with:
>
wow ! I'm perplex. You hit the point and I didnt think about this one.
I knew that @_ are aliases, but it didnt strike me, that $1 is a global
variable.
Like you imagined, I passed $1 as argument to my function. (which cant be
avoided easily, cause I use this function inside a different
s///e-operation). So the solution is simple, I just need to add 'my @d=@_'
at the beginning of my sub and use it inside.
thnx very very much. You leave me deep impressed about your knowledge and
imagination.
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Sun, 16 Sep 2001 17:14:10 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Similar file finder
Message-Id: <3ba4dde2.319a$116@news.op.net>
Perhaps you could take a look at the nilsimsa algorithm:
http://lexx.shinn.net/cmeclax/nilsimsa.html
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 16 Sep 2001 17:19:11 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: Similar file finder
Message-Id: <sa83d5m99ds.fsf@suntong.personal.users.sourceforge.net>
mjd@plover.com (Mark Jason Dominus) writes:
> Perhaps you could take a look at the nilsimsa algorithm:
Thanks a lot Mark!
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: 16 Sep 2001 09:35:28 -0700
From: remkon@nelvana.com (Remko Noteboom)
Subject: Unresolved symbol dynamically loading an xsub
Message-Id: <e3f38636.0109160835.26495390@posting.google.com>
What is the difference between embedding the perl interpreter into
an executable and embedding it it in a ".so"?
I have created an xsub which works when I embed perl into an executable,
but when I embed perl into a ".so", loading my xsub gives the following
error from the dynaloader:
Can't load '/usr/lib/perl5/site_perl/5.6.0/i386-linux/auto/Mel/Mel.so' for modul
e Mel: /usr/lib/perl5/site_perl/5.6.0/i386-linux/auto/Mel/Mel.so: undefined symb
ol: PL_markstack_ptr at /usr/lib/perl5/5.6.0/i386-linux/DynaLoader.pm line 200.
at perl_maya.pl line 5
Looking through the perl source code, it appears that this is a perl
symbol, however, I am not directly using it. I am not familiar enough
with the perl intrinsics to diagnose this and
I am not sure if my problem is in the xsub or in how I embeded perl
into my ".so".
Any help would be greadly appreciated.
remko.
------------------------------
Date: Sun, 16 Sep 2001 15:34:51 -0400
From: "William Grigg" <wgrigg@draper.com>
Subject: vbScript to Perl?
Message-Id: <9o2usr$gsm$1@news.draper.com>
I have a task where I need to make the same content available on several
types of web servers (IIS5, IIS4, apache) that are running on different
platforms (W2K, NT4, Linux, etc). They also need to do a little database
access and update. The best I have come up with so far is to use the Gallery
sample application available under MS Interdev, and to try to port it to the
Apache server. Here are some questions:
1. Is there an easier approach? Maybe some example that currently exists
that I have not discovered. Buying something from a third party is fine.
2. Is there a means of running ASP/vbScript stuff on Apache?
3. If 2. above is false, then is rewriting the Gallery example in Perl the
thing to do?
------------------------------
Date: Sun, 16 Sep 2001 19:46:08 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: vbScript to Perl?
Message-Id: <slrn9qa13r.pom.tim@vegeta.ath.cx>
Me parece que William Grigg <wgrigg@draper.com> dijo:
[ snippage ]
> 2. Is there a means of running ASP/vbScript stuff on Apache?
ChiliSoft ASP
http://www.chilisoft.com/
Third-party ASP environment for several web servers, including Apache.
I've never used it, but it may be a (commercial) solution to your
problem.
[ snip ]
HTH
--
Any emotion, if it is sincere, is involuntary.
-- Mark Twain
------------------------------
Date: Sun, 16 Sep 2001 21:16:26 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: vbScript to Perl?
Message-Id: <3BA516DD.D3C9CD73@rochester.rr.com>
William Grigg wrote:
>
> I have a task where I need to make the same content available on several
> types of web servers (IIS5, IIS4, apache) that are running on different
> platforms (W2K, NT4, Linux, etc). They also need to do a little database
> access and update. The best I have come up with so far is to use the Gallery
> sample application available under MS Interdev, and to try to port it to the
> Apache server. Here are some questions:
>
> 1. Is there an easier approach? Maybe some example that currently exists
> that I have not discovered. Buying something from a third party is fine.
>
> 2. Is there a means of running ASP/vbScript stuff on Apache?
>
> 3. If 2. above is false, then is rewriting the Gallery example in Perl the
> thing to do?
For portability, I doubt you'll ever beat Perl with DBI and standard
CGI. I would fully expect that everything would work on all platforms
with no changes other than possibly database connection strings.
--
Bob Walton
------------------------------
Date: 16 Sep 2001 10:03:02 -0700
From: sgarfunkle@hotmail.com (Jay McGavren)
Subject: Re: XML::XSLT - 'Can't call method "getNodeValue" on an undefined value'?
Message-Id: <6bb557e1.0109160903.5e01e276@posting.google.com>
> I have started to apply some modifications to the source
> code of XSLT.pm, but then stopped, when I saw that it seems
> there was too much to do. I refer to $VERSION = '0.32';.
Oh, boy. So this really is a bug in XML::XSLT? Has anyone even used
the module successfully? Maybe I should just give up until a more
stable version is released...
------------------------------
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 1757
***************************************