[25541] in Perl-Users-Digest
Perl-Users Digest, Issue: 7785 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 15 18:05:33 2005
Date: Tue, 15 Feb 2005 15:05:19 -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 Tue, 15 Feb 2005 Volume: 10 Number: 7785
Today's topics:
Re: A wide open niche in Perl publishing... <spamtrap@dot-app.org>
Re: Anybody know why pm.org is down? <jkeen_via_google@yahoo.com>
Re: forms, cgi - beginner question <jfcampbell@aol.com>
Re: forms, cgi - beginner question <noreply@gunnar.cc>
Re: forms, cgi - beginner question <1usa@llenroc.ude.invalid>
Re: forms, cgi - beginner question <1usa@llenroc.ude.invalid>
Re: forms, cgi - beginner question <spamtrap@dot-app.org>
Re: forms, cgi - beginner question <flavell@ph.gla.ac.uk>
Re: Mod_perl: can I share a database connection by putt <kkeller-usenet@wombat.san-francisco.ca.us>
perl corrupting my open files - mkfifo? <jeremy.slade@intel.com>
Re: perl corrupting my open files - mkfifo? <abigail@abigail.nl>
Re: perl corrupting my open files - mkfifo? <jeremy.slade@intel.com>
Re: perl corrupting my open files - mkfifo? <abigail@abigail.nl>
Re: Record Hash Data Structure (Newbie) <jgibson@mail.arc.nasa.gov>
Re: regular expression backreferences <jfcampbell@aol.com>
Re: regular expression backreferences (Anno Siegel)
Re: regular expression backreferences <mdudley@king-cart.com>
Re: regular expression backreferences <emschwar@pobox.com>
Re: regular expression backreferences <jgibson@mail.arc.nasa.gov>
Re: Sort hashes <phaylon@dunkelheit.at>
Re: Unexpected Result From Pipe Read xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Feb 2005 16:50:55 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: A wide open niche in Perl publishing...
Message-Id: <4PGdnaAejrxc84_fRVn-rw@adelphia.com>
J Krugman wrote:
> Unless I've been looking in all the wrong places, it seems to me
> that there's a wide open niche in Perl-related publishing (and in
> all of programming-related publishing, for that matter). I don't
> even know what to call the type of book I'm thinking of. It's
> something in the spirit of the (awesome) Perl Cookbook, but dedicated
> to larger-scale design issues, instead of bite-sized solutions.
I think you've been looking in the wrong places. The kind of large-scale
application design issues you're talking about aren't language-specific,
and books that talk about them tend to use pseudo-code and/or diagrams to
illustrate their points.
The assumption is that someone who's designing applications at that scale
will be familiar enough with the target language that they'll have no
problem translating the abstract ideas from the book, into concrete code in
the language of their choice.
Have a look at "Design Patterns", for example. Not a single line of Perl in
it, but still perfectly relevant for a Perl programmer who's designing a
large-scale application using OOD.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 15 Feb 2005 21:49:27 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Anybody know why pm.org is down?
Message-Id: <H7uQd.58501$g16.10386@trndny08>
ny10scn@yahoo.com wrote:
> Anybody know why pm.org is down? I googled this group and didn't
> necessarily find any sort of notice that pm.org has gone permanently
> offline. And anyway, whois.sc had an updated image as of earlier this
> month.
>
> So what gives. It was inaccessible to me as of 6am this morning, and
> now again as of 12 noon.
>
I confirm that it is down, though the site is pingable. The volunteers
who maintain it have been doing a lot of work on it in recent months, so
perhaps it is just offline for maintenance.
jimk
------------------------------
Date: 15 Feb 2005 11:08:08 -0800
From: "John" <jfcampbell@aol.com>
Subject: Re: forms, cgi - beginner question
Message-Id: <1108494488.090238.240950@z14g2000cwz.googlegroups.com>
Copy and paste accident. Let's try this one again:
I am trying to reconcile these two comments.
Is the web server irrelevant or is the web server the problem?
>> But I do not get "only output from the script."
>> I get the whole
>> shebang, as it were, with the word "print" etc.
>> in my browser window.
>That means your web server is not properly configured.
>> I am trying to work the example using the Web server supplied with
>> Mac OS X,10.3.8.
>> But If I make the internal sale with the demo, the target system
>> would be an NT or Linux machine.
>That is completely irrelevant
------------------------------
Date: Tue, 15 Feb 2005 20:39:20 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: forms, cgi - beginner question
Message-Id: <37f1baF5a23uoU2@individual.net>
John wrote:
>
> And here's example.pl:
> #!/usr/bin/perl -w
> print "This is example.pl speaking";
>
> When I hit submit, the address in the browser window changes
> to".../cgi-bin/example.pl"
> But I do not get "only output from the script." I get the whole
> shebang, as it were, with the word "print" etc. in my browser window.
Try http://my.execpc.com/~keithp/bdlogcgi.htm
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 15 Feb 2005 19:50:37 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: forms, cgi - beginner question
Message-Id: <Xns95FE970064992asu1cornelledu@127.0.0.1>
"John" <jfcampbell@aol.com> wrote in news:1108494488.090238.240950
@z14g2000cwz.googlegroups.com:
> Copy and paste accident. Let's try this one again:
>
> I am trying to reconcile these two comments.
Whose comments? Please make proper attributions when you quote someone
(in this case, me).
> Is the web server irrelevant or is the web server the problem?
>
>>> But I do not get "only output from the script."
>>> I get the whole shebang, as it were, with the word "print" etc.
>>> in my browser window.
>
>>That means your web server is not properly configured.
>
> >> I am trying to work the example using the Web server supplied with
> >> Mac OS X,10.3.8.
> >> But If I make the internal sale with the demo, the target system
> >> would be an NT or Linux machine.
>
>>That is completely irrelevant
The details of your web server configuration are completely off-topic
here. However, if your web server is echoing the contents of a script
rather than running your script, then your web server is misconfigured.
These two statements have nothing whatsoever to do with each other. I do
not see the source of your confusion.
So, the first thing to do is to configure your web server correctly.
Second, you should look at the CGI spec to make sure the output your
programs produce conforms to the spec.
You have already stated that you don't need any Perl advice, but I will
point out that you should read
perldoc CGI
and
perldoc -q CGI
Sinan.
------------------------------
Date: Tue, 15 Feb 2005 19:53:01 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: forms, cgi - beginner question
Message-Id: <Xns95FE9768DB03Aasu1cornelledu@127.0.0.1>
"John" <jfcampbell@aol.com> wrote in news:1108494227.994002.6410
@f14g2000cwb.googlegroups.com:
>>The common gateway interface (CGI) is a little more complex than you
>> assume.
>
> This might well be the answer to my question. Just not the answer I was
> hoping for. I was looking for a proof of concept. The concept was that
> this was doable with a certain amount of work.
Whatever "it" is, I assure you that it is doable. I have shown you how to
produce the output you expected from your script.
>>The command "perldoc CGI" may help get you started.
>
> Maybe for some. For me, it's starting in the middle.
As I pointed out, the CGI spec is readily available on the WWW.
Since you know C and Perl, it should not be too hard to follow it.
Sinan.
------------------------------
Date: Tue, 15 Feb 2005 16:30:08 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: forms, cgi - beginner question
Message-Id: <X9KdnW0saet_9I_fRVn-gA@adelphia.com>
While the previous advice - use CGI.pm, warnings, and strict, read the FAQ,
etc. - is true, it doesn't really answer the question.
John wrote:
> Page 8 says:
> "...when a Web server receives a request for a file contained in in the
> subdirectory cgi-bin, it knows that the file is a cgi script and will
> run it and return only output from the script.
That's true in general, but be aware that cgi-bin is usually *not* a real
subdirectory that exists in your main document directory. It's usually
mapped to a different directory entirely.
> I am trying to work the example using the Web server supplied with Mac
> OS X,10.3.8.
Okay, that means most of your web content goes in:
/Library/WebServer/Documents
But, cgi-bin (in the URL) translates to this directory:
/Library/WebServer/CGI-Executables
> But If I make the internal sale with the demo, the target system would
> be an NT or Linux machine.
The URLs wouldn't change in that case, but the actual directories behind
them almost certainly would.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 15 Feb 2005 22:44:30 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: forms, cgi - beginner question
Message-Id: <Pine.LNX.4.61.0502152239290.8346@ppepc56.ph.gla.ac.uk>
On Tue, 15 Feb 2005, Sherm Pendley wrote:
> John wrote:
>
> > Page 8 says:
> > "...when a Web server receives a request for a file contained in in the
> > subdirectory cgi-bin, it knows that the file is a cgi script and will
> > run it and return only output from the script.
>
> That's true in general,
Excuse me stepping in here, but it's by no means "true in general",
rather, "it's a widespread convention".
(Of course, this is nothing specific to Perl. Such questions would be
better addressed on an appropriate web server configuration group.
Not that you need me to lecture you on that, but some readers...)
> but be aware that cgi-bin is usually *not* a real subdirectory that
> exists in your main document directory. It's usually mapped to a
> different directory entirely.
Indeed.
------------------------------
Date: Tue, 15 Feb 2005 14:16:59 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Mod_perl: can I share a database connection by putting it in the startup-script?
Message-Id: <sv8ae2x3bq.ln2@goaway.wombat.san-francisco.ca.us>
On 2005-02-15, Brian McCauley <nobull@mail.com> wrote:
>
> When you say 'can be configured' this implies that it is not the default
> behaviour of Apache::DBI, but AFIAK this is the default behaviour of
> Apache::DBI, indeed what else doe Apache::DBI do?
Well, yes, you're correct, it's all Apache::DBI does. When I said 'can
be configured', I meant that you do need to modify your httpd.conf file
or the startup file configured in httpd.conf. Simply installing
Apache::DBI and even using it in your scripts (which the docs tell you
not to do anyway) isn't sufficient. (I certainly should have been more
clear, and apologize for the misunderstanding.)
> Oooh, is Apache::DBI for mod_perl2 available? I must go get it.
Gaah, another misstatement by me! I don't know whether it is or not.
Allegedly you can use Apache::compat to use mod_perl1 modules with
mod_perl2, but I've never actually tried it. That'd be another good
question for the mod_perl mailing list.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information
------------------------------
Date: Tue, 15 Feb 2005 12:19:24 -0700
From: Jeremy Slade <jeremy.slade@intel.com>
Subject: perl corrupting my open files - mkfifo?
Message-Id: <cuthvt$vka$1@news01.intel.com>
I'm running perl 5.6.1 on linux i686 kernel 2.6.8
I had a very strange experience this morning that is rather alarming to
me. I was running a perl script that has been running many hundreds of
times before... I had executed it with the incorrect options, so I hit
Ctrl-C to kill it.
Somehow the result of this is that every file to which I had an open
handle became a unix FIFO on disk -- as though the file was removed,
then mkfifo was run in it's place. e.g. it look like this afterwards:
% ls -lF foo
prw-rw-r-- 1 jgs jgs 0 Feb 15 10:39 foo|
Some file were opened with IO::File->new(), some were opened via perl's
'do' function -- and it least one case was a symlink on a path to an
open file, but not the actual file itself.
Can anyone please explain how this could happen? I check the perl 5.6.1
source code for all occurrences of mkfifo or mknod, I don't see anything
where it is used except in the xs interface stuff, nothing internal.
This is not only baffling, but also alarming that this could happen.
Thanks in advance,
Jeremy
------------------------------
Date: 15 Feb 2005 22:00:29 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: perl corrupting my open files - mkfifo?
Message-Id: <slrnd14s7t.ov1.abigail@alexandra.abigail.nl>
Jeremy Slade (jeremy.slade@intel.com) wrote on MMMMCLXXXVI September
MCMXCIII in <URL:news:cuthvt$vka$1@news01.intel.com>:
$$ I'm running perl 5.6.1 on linux i686 kernel 2.6.8
$$
$$ I had a very strange experience this morning that is rather alarming to
$$ me. I was running a perl script that has been running many hundreds of
$$ times before... I had executed it with the incorrect options, so I hit
$$ Ctrl-C to kill it.
$$
$$ Somehow the result of this is that every file to which I had an open
$$ handle became a unix FIFO on disk -- as though the file was removed,
$$ then mkfifo was run in it's place. e.g. it look like this afterwards:
$$
$$ % ls -lF foo
$$ prw-rw-r-- 1 jgs jgs 0 Feb 15 10:39 foo|
$$
$$ Some file were opened with IO::File->new(), some were opened via perl's
$$ 'do' function -- and it least one case was a symlink on a path to an
$$ open file, but not the actual file itself.
$$
$$ Can anyone please explain how this could happen? I check the perl 5.6.1
$$ source code for all occurrences of mkfifo or mknod, I don't see anything
$$ where it is used except in the xs interface stuff, nothing internal.
$$ This is not only baffling, but also alarming that this could happen.
Can you repeat the procedure? Does it happen with 5.8.6 as well? If so,
can you post a small piece of code that shows this behaviour? If you
can't repeat it, how do you know this problem is due to a problem with Perl?
Abigail
--
perl -wle 'eval {die ["Just another Perl Hacker"]}; print ${$@}[$#{@${@}}]'
------------------------------
Date: Tue, 15 Feb 2005 15:23:42 -0700
From: Jeremy Slade <jeremy.slade@intel.com>
To: abigail@abigail.nl
Subject: Re: perl corrupting my open files - mkfifo?
Message-Id: <4212766E.1070200@intel.com>
Abigail wrote:
> Jeremy Slade (jeremy.slade@intel.com) wrote on MMMMCLXXXVI September
> MCMXCIII in <URL:news:cuthvt$vka$1@news01.intel.com>:
> $$ I'm running perl 5.6.1 on linux i686 kernel 2.6.8
> $$
> $$ I had a very strange experience this morning that is rather alarming to
> $$ me. I was running a perl script that has been running many hundreds of
> $$ times before... I had executed it with the incorrect options, so I hit
> $$ Ctrl-C to kill it.
> $$
> $$ Somehow the result of this is that every file to which I had an open
> $$ handle became a unix FIFO on disk -- as though the file was removed,
> $$ then mkfifo was run in it's place. e.g. it look like this afterwards:
> $$
> $$ % ls -lF foo
> $$ prw-rw-r-- 1 jgs jgs 0 Feb 15 10:39 foo|
> $$
> $$ Some file were opened with IO::File->new(), some were opened via perl's
> $$ 'do' function -- and it least one case was a symlink on a path to an
> $$ open file, but not the actual file itself.
> $$
> $$ Can anyone please explain how this could happen? I check the perl 5.6.1
> $$ source code for all occurrences of mkfifo or mknod, I don't see anything
> $$ where it is used except in the xs interface stuff, nothing internal.
> $$ This is not only baffling, but also alarming that this could happen.
>
>
> Can you repeat the procedure? Does it happen with 5.8.6 as well? If so,
> can you post a small piece of code that shows this behaviour? If you
> can't repeat it, how do you know this problem is due to a problem with Perl?
That's the problem - I can't reproduce it, and can't explain it based on
anything I'm doing are can find in the perl code. But it definitely
happened as a result of running the perl script. So I'm looking for any
possible explanation as to how something like this could happen.
Thanks,
Jeremy
------------------------------
Date: 15 Feb 2005 22:51:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: perl corrupting my open files - mkfifo?
Message-Id: <slrnd14v7f.2e8.abigail@alexandra.abigail.nl>
Jeremy Slade (jeremy.slade@intel.com) wrote on MMMMCLXXXVI September
MCMXCIII in <URL:news:4212766E.1070200@intel.com>:
`' Abigail wrote:
`' > Jeremy Slade (jeremy.slade@intel.com) wrote on MMMMCLXXXVI September
`' > MCMXCIII in <URL:news:cuthvt$vka$1@news01.intel.com>:
`' > $$
`' > $$ [ Filesystem problem blamed on Perl ]
`' >
`' > Can you repeat the procedure? Does it happen with 5.8.6 as well? If so,
`' > can you post a small piece of code that shows this behaviour? If you
`' > can't repeat it, how do you know this problem is due to a problem with Perl
`'
`' That's the problem - I can't reproduce it, and can't explain it based on
`' anything I'm doing are can find in the perl code. But it definitely
`' happened as a result of running the perl script. So I'm looking for any
`' possible explanation as to how something like this could happen.
How do you know?
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: Tue, 15 Feb 2005 12:48:24 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Record Hash Data Structure (Newbie)
Message-Id: <150220051248242647%jgibson@mail.arc.nasa.gov>
In article <1108438617.406599.291620@z14g2000cwz.googlegroups.com>,
<rajasekaran.natarajan@gmail.com> wrote:
> Hi all!
> Yeah I included another hash for element data for the second part. but
> I do not know how to acess the hash %grid using the values I get from
> %element hash (check the print loop)
As Xho pointed out, a hash is probably not the best data structure for
300,000 records. In any case, you are not using hashes properly.
>
Where is 'use strict;' ?
> my $file1 = "test.dat";
> my ($identifier,$gridNo,$cp,$xcor,$ycor,$zcor,$cd);
Do not declare variables outside of a block that are used only within
that block.
> open(DECK,"$file1") || die ("Cant open input file \"$file1\", Unable to
> Find, Check the file name and path");
Don't quote unnecessarily; use variable file handles, use 3-argument
open, let Perl and the system tell you what is wrong:
open($fh,'<',$file1) or die("Can't open $file1: $!");
Here, declare some global arrays (not hashes) to hold your data:
my( @grid, @element );
> while($line= <DECK>){
while( my $line = <$fh> ) {
> if ($line =~ m/^GRID/) {
> ($identifier,$gridNo,$cp,$xcor,$ycor,$zcor,$cd)= unpack("A8 A8 A8 A8
> A8 A8 A8",$line);
my( $identifier, ...
> %grid = (
> $gridNo => {cp => $cp, xcor => $xcor, ycor => $ycor, zcor => $zcor,},
> );
You are assigning to %grid each time through the loop, thereby
overwriting your previous data. If you really want to use a hash, you
should be doing this:
$grid{$gridNo} = { id => $gridNo, cp => $cp, ... };
but you might want to use an array of hashes instead:
push(@grid, { id => $gridNo, cp => $cp, ... });
or even an array of arrays (which I would recommend for simplicity and
efficiency:
push(@grid, [ $gridNo, $cp, $xcor, $ycor, $zcor ] );
> }
> elsif($line =~ m/^CQUAD4/) {
> ($eId,$elementNo,$grid1,$grid2,$grid3,$grid4) = unpack("A8 A8 x8 A8
> A8 A8 A8",$line);
my( $eId, ... ) = ...;
> %element = (
> $elementNo => {ETYPE=> $eId, con1 => $grid1, con2 => $grid2, con3=>
> $grid3, con4 => $grid4},
> );
Either
$element{$elementNo} =
or
push(@element, { ... } );
> }
> foreach $elementNo (keys %element) {
> print
>
> "\n$element{$elementNo}->{ETYPE},$elementNo,$element{$elementNo}->{con1},$elem
> ent{$elementNo}->{con2},$element{$elementNo}->{con3},$element{$elementNo}->{co
> n4}
> \n";
> #here I wanted to print grid1-grid4 (from `con1`-`con4` value of
> %element) and its x,y,z corordinates (x,y,z needs tobe picked from like
> %grid{con1}->{xcor} is it possible
> #I dont know how to do that I tried many ways.
> }
> }
> close(DECK);
In future posts, please try to make all of your lines no longer than
60-70 characters for readability.
>
> My Present Goal is to print like this
>
> Element1 grid1 grid2 grid3 grid4 (-> this line is ok)
> grid1 xcor ycor zcor -> these four lines I could not get.
> grid2 xcor ycor zcor
> grid3 xcor ycor zcor
> grid4 xcor ycor zcor
> Element2 grid1 grid2 grid3 grid4
> grid1 xcor ycor zcor
> grid2 xcor ycor zcor
> grid3 xcor ycor zcor
> grid4 xcor ycor zcor
>
You seem to imply some sort of relation between the GRID lines and the
CQUAD4 lines, but you haven't explained what it is. That would
definitely influence the choice of data structure to use and the method
for fetching and printing. Try showing some relevant, sample data next
time. Use the special <DATA> file handle and include the data at the
end of your program after a '__DATA__' line.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: 15 Feb 2005 11:24:42 -0800
From: "John" <jfcampbell@aol.com>
Subject: Re: regular expression backreferences
Message-Id: <1108495482.827880.310300@l41g2000cwc.googlegroups.com>
Kind of want to know more about the actual problem.
Just based on what's there, my inclination would be to create an
intermediate string, and mark it up to where you could use split.Then
loop through the split results.
But I may be fooled by the stripped-down example here.
------------------------------
Date: 15 Feb 2005 19:27:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regular expression backreferences
Message-Id: <cutiep$nm8$1@mamenchi.zrz.TU-Berlin.DE>
Marshall Dudley <mdudley@king-cart.com> wrote in comp.lang.perl.misc:
> Given the following:
>
> $string = "start:a-b,c-d,e-f";
>
> $string =~ /start:(?:(\w+)\-(\w+),?)+/;
> print "1 -> $1=$2\n2 -> $3=$4\n3 -> $5=$6\n";
>
> I would expect:
> 1 -> a=b
> 2 -> c=d
> 3 -> e=f
>
>
> but am getting:
> 1 -> e=f
> 2 -> =
> 3 -> =
>
> Is there any way to loop an unknown number of pairs, and get them shoved
> into the backreferences instead of them always overwriting the first
> two?
No. As you seem to have realized, the correspondence of capturing parens
to $1, $2, ... is static. It depends only on the text of the regex, not
the way it is matched.
> This is a simplication of the actual problem and I cannot use the
^^^^^^^^^^^^
... and this is another.
> g)lobal designation in the match due to other constraints.
You mention "other constraints", but don't specify them. That makes it
impossible to suggest an alternative.
Anno
------------------------------
Date: Tue, 15 Feb 2005 14:39:31 -0500
From: Marshall Dudley <mdudley@king-cart.com>
Subject: Re: regular expression backreferences
Message-Id: <42124FF2.8D45FB1A@king-cart.com>
John wrote:
> Kind of want to know more about the actual problem.
>
> Just based on what's there, my inclination would be to create an
> intermediate string, and mark it up to where you could use split.Then
> loop through the split results.
>
> But I may be fooled by the stripped-down example here.
Well, I am trying to get a mod_rewrite regular expression right for using
in an Apache RewriteRule line. I am testing the line in perl to make sure
it works right before putting it into the apache configuration since it
if it wrong, it could crash the server for everyone and all
applications. I was hoping to get it done in one RewriteRule. Basically
I need to take the form of:
/abc/def-ghi/jkl-mno/..... with any number of terms and convert it to:
cgi-bin/script.cgi?store=abc&def=ghi&jkl=mno....
I was hoping to do it with one RewriteRule, and without the complication
of calling a perl script to do it with, since I have never used the
RewriteRule before and am just now trying to learn/use it. Unfortunately,
I cannot simply test this in the final configuration until I know I have
it right since an error would likely crash the web server for everyone
and everything on the box.
I realize this should be asked in the Apache newsgroups normally, but the
question was on regular expressions, and the knowlege on regular
expressions is much better here.
Thanks,
Marshall
------------------------------
Date: Tue, 15 Feb 2005 13:22:54 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: regular expression backreferences
Message-Id: <etooeelbmjl.fsf@wilson.emschwar>
Marshall Dudley <mdudley@king-cart.com> writes:
> Well, I am trying to get a mod_rewrite regular expression right for using
> in an Apache RewriteRule line.
...
> I was hoping to get it done in one RewriteRule. Basically
> I need to take the form of:
>
> /abc/def-ghi/jkl-mno/..... with any number of terms and convert it to:
>
> cgi-bin/script.cgi?store=abc&def=ghi&jkl=mno....
You might want to go to an Apache group to figure out how to use
regular expressions in an Apache config file; we don't generally know
much about that sort of thing here. However, if you want a Perl
solution, you could use mod_perl on the server, and setup a
PerlTransHandler to rewrite the URI for you. The code in the handler
might look something like (untested, use at your own risk):
sub handler {
my $r = shift;
my $uri = $r->uri;
my ($store, @args);
return Apache::DECLINED if $r->uri =~ m|^/cgi-bin/|;
# strip the store name off the front
$uri =~ s|^/([^/]+)||);
push @args, "store=$1";
# loop over the path components
while($uri =~ m|/([^/]+)|g) {
my $parm = $1;
$parm =~ s/-/=/;
push @args, $parm;
}
# set up the proper url to redirect to
$r->uri('/cgi-bin/script.cgi');
$r->args(join('&', @args));
return Apache::DECLINED;
}
I suppose you could do something fancy with File::Spec::splitdir
instead of looping over the regex the way I did, but I suspect that
might only work on Unix-like systems. A split-based approach would
likely be faster, but I can't be bothered to benchmark it.
This is the first PerlTransHandler I've written, but seemed fairly simple,
based on:
<http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlTransHandler>
Comments from more experienced mod_perl'ers welcome.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Tue, 15 Feb 2005 15:02:17 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: regular expression backreferences
Message-Id: <150220051502175395%jgibson@mail.arc.nasa.gov>
In article <42123F5A.60EC93D0@king-cart.com>, Marshall Dudley
<mdudley@king-cart.com> wrote:
> Given the following:
>
> $string = "start:a-b,c-d,e-f";
>
> $string =~ /start:(?:(\w+)\-(\w+),?)+/;
> print "1 -> $1=$2\n2 -> $3=$4\n3 -> $5=$6\n";
>
> I would expect:
> 1 -> a=b
> 2 -> c=d
> 3 -> e=f
>
>
> but am getting:
> 1 -> e=f
> 2 -> =
> 3 -> =
>
> Is there any way to loop an unknown number of pairs, and get them shoved
> into the backreferences instead of them always overwriting the first
> two?
No, but you can capture successive pairs into an array if they are
always separated by a dash:
#!/usr/local/bin/perl
#
use strict;
use warnings;
my $string = 'start:a-b,c-d,e-f';
my @s = ($string =~ m/(\w+)-(\w+)/g);
print "@s\n";
Produces:
a b c d e f
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Tue, 15 Feb 2005 20:02:05 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Sort hashes
Message-Id: <pan.2005.02.15.19.02.03.739913@dunkelheit.at>
Raj wrote:
> $ips{"F1234"}{"telephone"} = "02088887777" $ips{"F1234"}{"charge"} = 1000
> $ips{"F1234"}{"err_type"} = 0
>
> $ips{"F6638"}{"telephone"} = "02077776666" $ips{"F6638"}{"charge"} = 500
> $ips{"F6638"}{"err_type"} = 2
> ...
> I need to sort it using the key "err_type"....is this easy? I've never
> understood sorting in Perl and so would appreciate any help you can give
> me. "err_type" is always a number, if that's relevant!
How about:
sub errtype { $ips{ $a }{err_type} <=> $ips{ $b }{err_type} }
for( sort errtype keys %ips ) {
print "$_\n";
}
This gives the keys of your (level 0) hashes to sort. Sort uses a function
here, gives it $a and $b (the two values that get compared to tell which
is higher). These two vars (two keys of your level 0 hash) we use, well,
as keys for your level 0 hash, but we don't compare (maybe you lookup the
<=> operator) the keys (F6683) but the values of the err_type field in the
hashref saved as value to your level 0 hash.
g,phay
--
http://www.dunkelheit.at/
bellum omnium pater.
------------------------------
Date: 15 Feb 2005 21:54:31 GMT
From: xhoster@gmail.com
Subject: Re: Unexpected Result From Pipe Read
Message-Id: <20050215165430.981$iB@newsreader.com>
John <john_tilly@hotmail.com> wrote:
> All:
>
> I have set up a named pipe to transfer data between threads. While the
> transfer is successful, I'm perplexed by the system messages I trap along
> the way. As a necessity, I start attempting to read from the pipe ahead
> of writing to the pipe using:
>
> <code snip>
>
> do {
> open (FIFO_READ, "< $FIFO");
> if ($!) {
from perldoc perlvar:
$! If used numerically, yields the current value of the C
"errno" variable, or in other words, if a system or library
call fails, it sets this variable. This means that the
value of $! is meaningful only immediately after a failure:
Note the last sentence. You check the open itself for failure. Only if
the opened failed should you inspect $!.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
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 7785
***************************************