[30454] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1697 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 7 16:09:47 2008

Date: Mon, 7 Jul 2008 13:09:12 -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           Mon, 7 Jul 2008     Volume: 11 Number: 1697

Today's topics:
    Re: Authen::Captcha - How do I make it display the imag <hjp-usenet2@hjp.at>
    Re: Authen::Captcha - How do I make it display the imag <spamtrap@dot-app.org>
    Re: Authen::Captcha - How do I make it display the imag <ginvalicde@gmail.com>
    Re: Authen::Captcha - How do I make it display the imag <ginvalicde@gmail.com>
    Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? <BLOCKSPAMfishfry@your-mailbox.com>
    Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? <cwilbur@chromatico.net>
    Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? <spamtrap@dot-app.org>
    Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? <joost@zeekat.nl>
    Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? <cwilbur@chromatico.net>
    Re: Generating fancy/pretty documents <greymausg@mail.com>
    Re: Generating fancy/pretty documents <hjp-usenet2@hjp.at>
        session <dev.b.85@gmail.com>
        session <dev.b.85@gmail.com>
    Re: session <rkb@i.frys.com>
    Re: session <spamtrap@dot-app.org>
        Value of "Programming perl" 1st Ed.? <spamtrap@dot-app.org>
    Re: Want regex s/// to replace only nth occurrence <mritty@gmail.com>
    Re: Want regex s/// to replace only nth occurrence <hjp-usenet2@hjp.at>
    Re: Want regex s/// to replace only nth occurrence <wahab@chemie.uni-halle.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 7 Jul 2008 17:35:43 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Authen::Captcha - How do I make it display the image
Message-Id: <slrng74duf.btd.hjp-usenet2@hrunkner.hjp.at>

On 2008-07-06 20:25, Sherman Pendley <spamtrap@dot-app.org> wrote:
> "Gordon Corbin Etly" <ginvalidce@gmail.com> writes:
>> Sherman Pendley wrote:
>>> <news.freedom2surf.net> writes:
>>
>>> > Hi,
>>> > My PERL is VERU rusty.
>>
>>> Quick tip: It's Perl, not PERL.
>>
>> PERL is fine is you mean it to mean "Practical Extraction and Report 
>> Language"
>
> The Perl docs clearly state otherwise. From "perldoc perlfaq1":

Can you please stop arguing this with with Etly? You won't convince him,
but if you want to continue this quixotic crusade, please do it via
email.

	hp


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

Date: Mon, 07 Jul 2008 11:57:55 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: Authen::Captcha - How do I make it display the image
Message-Id: <m1skuln0u4.fsf@dot-app.org>

"Gordon Corbin Etly" <ginvalidce@gmail.com> writes:

> Please explain your logic

Larry Wall calls it "Perl." His language, his creation, his chosen
name for it. He's the "Benevolent Dictator" in this community, and no
one else gets a vote. :-)

Here's an interview where he discusses the origin of the name:

    <http://www.linuxjournal.com/article/3394>

Note the ordering - the name came first, then he came up with "gloss"
like "Practical Extraction and Report Language" or "Pathologically
Eclectic Rubbish Lister" to fit the name. Also note that he explicitly
mentions that it should be written as "perl" to refer to the program,
and "Perl" to refer to the language.

Along similar lines, the name "Ford" has had similar "gloss" applied
to it over the years. "Found On Road Dead," "F***ing Old Rebuilt
Dodge," etc. But those are backronyms, concocted after the fact. The
name of the company is still Ford, not FORD.

Having said that, I do think you have a good point about "perldoc
perl." You've arrived at the wrong conclusion, but I can easily see
how you got there. Given that the correct spelling of the name is
"Perl", the title of that page is misleading. It leads to pointless
debates about which doc page is "more right," "perl" or "perlfaq1". An
innocuous phrase such as "A programming language invented by Larry
Wall" would be far less confusing.

> I thought that was the point of the alternative method I mentioned. 
> There are two common way it's done. Generating the image, saving it 
> somewhere and outputting the HTML that references it, or existing HTML 
> pages reference a script directly from an IMG tag that outputs the raw 
> generated image data (for the appropiate image format, be it png, jpg, 
> gif...) The former is the way the op did it, the latter is the other way 
> I've seen it done :)

It's a trade-off between security and performance. Re-using a limited
set of CAPTCHA phrases means you can generate each image once and
cache it for better performance. Unique phrases are more difficult for
bots to predict, but you have to generate the image every time.

I'm rather surprised that Authen::Captcha doesn't support both
options, given that, as you said, both are commonly used.

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Mon, 7 Jul 2008 09:43:20 -0700
From: "Gordon Corbin Etly" <ginvalicde@gmail.com>
Subject: Re: Authen::Captcha - How do I make it display the image
Message-Id: <6devdaF27sl4U1@mid.individual.net>

Uri Guttman wrote:
>>>>>> "GCE" == Gordon Corbin Etly <ginvalidce@gmail.com> writes:

> > > are you going to go through this again? no decent perl hacker ever
> > > uses PERL.

> > Frankly, I would think any decent perl hacker would of read the 
> > first
> > document of the language he or she is using, which clearly states,
> > "Practical Extraction and Report Language", and if you write it in
> > short hand, the result is "PERL", there's just no way around that.

> and the FAQ contradicts that with a quote from larry wall that perl
> was never an acronym so PERL is wrong.

> do you think the docs which are written by p5p would know more
> than larry about how he named the language?

Here, try this one on for size:


< http://tinyurl.com/6joyuz >  <1>
Linux Magazine, Friday, October 15th, 1999, Larry Wall:

" Anyway, I did some sneaky things to make sure Perl developed a healthy
" culture. While we took ourselves very seriously in some ways, we also
" tried to laugh at ourselves occasionally. Perl not only stands for the
" Practical Extraction and Report Language, but it also stands for the
" Pathologically Eclectic Rubbish Lister.


This was written by Larry Wall _him_self_, and you are still going to 
argue that "Practical Extraction and Report Language" is wrong to use? 
Larry Wall never said it could _not_ be used and I dare you to cite 
otherwise.

Just because a group of people hold a certain view, just because a few 
prominent people believe it, that doesn't make that view correct, and it 
certainly doesn't make it right to force such a view on other people. 
You have no real authority - no one on Usenet does. What you and others 
do is create the perception of authority and then misuse it to influence 
others based on a poorly founded group-based belief. Get over yourselves 
and stop trying to dictate something so trivial as the capitalization of 
a single word.

In the grand scheme of things: who really cares this much? I think there 
are better things to worry about than to constantly tell people how to 
write the word "Perl", "perl", etc, and then to use false arguments to 
defend it.




<1> 
http://209.85.141.104/search?q=cache:lk3LdszM5mgJ:www.linux-mag.com/id/322+larry+wall+%22%22Practical+Extraction+and+Report+Language%22&hl=en&ct=clnk&cd=38&gl=us


-- 
Gordon 




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

Date: Mon, 7 Jul 2008 09:51:19 -0700
From: "Gordon Corbin Etly" <ginvalicde@gmail.com>
Subject: Re: Authen::Captcha - How do I make it display the image
Message-Id: <6devs8F29jsdU1@mid.individual.net>

Peter J. Holzer wrote:

> Can you please stop arguing this with with Etly? You won't convince
> him, but if you want to continue this quixotic crusade, please do it
> via email.

Fair enough.

After my last reply to him here, if he still fails to see reason, I have 
nothing more to say to him.

He he or anyone else really want to contact me to discuss this or 
anything else, send email here:

My true email is: $(perl -e 'print 
"".reverse(q{moc.liamg@ylte.nodrog})')



-- 
Gordon 




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

Date: Mon, 07 Jul 2008 11:15:41 -0700
From: fishfry <BLOCKSPAMfishfry@your-mailbox.com>
Subject: Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?
Message-Id: <BLOCKSPAMfishfry-36071A.11154107072008@comcast.dca.giganews.com>

In article <x7iqvid01d.fsf@mail.sysarch.com>,
 Uri Guttman <uri@stemsystems.com> wrote:

> >>>>> "f" == fishfry  <BLOCKSPAMfishfry@your-mailbox.com> writes:
> 
>   f> In article <5a76k5-aaj.ln1@blue.stonehenge.com>,
>   f>  PerlFAQ Server <brian@stonehenge.com> wrote:
> 
> 
>   >> Perl 6 is the next major version of Perl, but it's still in development
>   >> in both its syntax and design. The work started in 2002 and is still
>   >> ongoing.
> 
>   f> And going, and going, and going ...
> 
>   f> Perl 6 is the Energizer Bunny of failed software development projects.
> 
>   f> Flame away.
> 
> nothing to flame about. you know not from perl6 nor the people and
> energy going into it nor the plans. flamebait like this (and anonymous
> at that) is meaningless.
> 
>


Uri, sadly I do know from Perl 6, the people, the energy, and the plans. 
However, things such as people, energy, and plans, are what economists 
(and programmers!) call inputs.

Nobody, least of all me, is complaining about the people, energy, and 
plans around Perl 6. The problem is the lack of output.

I speak as a frustrated longtime Perl developer who sees the jobs and 
the entire industry moving away from Perl not for technical reasons, but 
because the people who manage Perl killed the brand. 

I don't know whether this discussion is on topic for this newsgroup or 
not; but the discussion is certainly not meaningless.

The Perl 6 team is guilty of both second-system syndrome AND Osborning 
(announcing a future product that kills off your current product).

The effect on accomplished Perl programmers is very meaningful. I'm 
sorry to hear that people find this conversation "meaningless." 

It's the Perl community, what's left of it, that's in denial.

My point, which is arguable but certainly not meaningless, is that if 
Perl 6 came out tomorrow and worked perfectly and implemented all 
possible features, it would still be a failure. It's years late, and the 
rest of the world has moved on.


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

Date: Mon, 07 Jul 2008 14:43:56 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?
Message-Id: <86hcb1mt5f.fsf@mithril.chromatico.net>

>>>>> "f" == fishfry  <BLOCKSPAMfishfry@your-mailbox.com> writes:

    f> I speak as a frustrated longtime Perl developer who sees the jobs
    f> and the entire industry moving away from Perl not for technical
    f> reasons, but because the people who manage Perl killed the brand.

This is not what I see at all.

I've worked for three different companies in the past five or six years
that wanted to hire more Perl people but couldn't find any.

So a company has two or three really good Perl people, who are getting
the job done.  Then they expand, and they look for more good Perl
people.  And what they find is that the people who know Perl fall into
two broad groups:  the relative newbies, who know just enough to be
dangerous, and have lots of bad habits that will need to be broken; and
the experts, who are already gainfully employed and need a *really*
sweet offer to lure them away.

Sooner or later, some upper manager says, "Why are we using Perl when we
can't find qualified Perl programmers?  Hell, $university just graduated
2000 computer science majors who all need jobs, maybe we should be
looking at Java instead."  And then there's one fewer company using Perl
for new development, and one fewer reason for all those newbie Perl
programmers to develop professional programming skills; and the
experienced Perl experts jump ship for another company.

The managers who make long-term decisions don't know the difference
between Perl 5 and Perl 6, and largely don't care.  They know that if
they use Perl, of either flavor, they can't find enough people to get
the work done.  This is doing more harm to Perl than anything else.

    f> My point, which is arguable but certainly not meaningless, is
    f> that if Perl 6 came out tomorrow and worked perfectly and
    f> implemented all possible features, it would still be a
    f> failure. It's years late, and the rest of the world has moved on.

I don't think "failure" is the right word here.  If Perl 6 works
according to design, it will be both beautiful and useful, which is what
it set out to be.  It's an open-source project: popularity is not the
primary, or even secondary or tertiary, criterion for success.

And if you want to see how it might get adopted, don't look at the shift
from Perl 4 to Perl 5; look at the shift from Perl or Java to Ruby,
especially of the Ruby on Rails variety.

Finally, if you want to be taken seriously, have the courtesy of signing
your real name.  If you don't take your words seriously enough to stand
behind them, why should anyone else?

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Mon, 07 Jul 2008 15:05:54 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?
Message-Id: <m1iqvh1pm5.fsf@dot-app.org>

Charlton Wilbur <cwilbur@chromatico.net> writes:

> I've worked for three different companies in the past five or six years
> that wanted to hire more Perl people but couldn't find any.

Do you know anyone who's willing to pay for relocation to Boston? I'd
love to get back up to Beantown. I'm stuck in the sticks right now,
and it's a chicken-n-egg situation. Moving takes money, but I have to
move to make any. :-(

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Mon, 07 Jul 2008 21:17:47 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?
Message-Id: <87iqvh5wro.fsf@zeekat.nl>

Charlton Wilbur <cwilbur@chromatico.net> writes:

>>>>>> "f" == fishfry  <BLOCKSPAMfishfry@your-mailbox.com> writes:
>
>     f> I speak as a frustrated longtime Perl developer who sees the jobs
>     f> and the entire industry moving away from Perl not for technical
>     f> reasons, but because the people who manage Perl killed the brand.
>
> This is not what I see at all.
>
> I've worked for three different companies in the past five or six years
> that wanted to hire more Perl people but couldn't find any.

Same here. There aren't as many perl jobs as there are java jobs, but
the good programmers are very hard to find. Also, there are so many
java programmers willing to take a job at relatively low rates that a
fairly experienced Perl programmer here can probably get paid more
than an equivalently experienced java programmer.

Exactly what this means in the long run I don't know. But if I had to
guess I wouldn't bet on either Java or Perl as the way to get
well-paying interesting jobs. And if you want to keep working as a
developer, binding yourself to a single language is probably not a
good idea anyway (if only because doing multiple interesting languages
is a good way to get better as a developer).

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Mon, 07 Jul 2008 15:48:31 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?
Message-Id: <868wwdmq5s.fsf@mithril.chromatico.net>

>>>>> "JD" == Joost Diepenmaat <joost@zeekat.nl> writes:

    JD> Exactly what this means in the long run I don't know. But if I
    JD> had to guess I wouldn't bet on either Java or Perl as the way to
    JD> get well-paying interesting jobs. 

Networking with competent technical people is the way to get interesting
jobs that pay well -- it happens independently of the technology.

Running your own company is the best way to get an interesting job,
although paying well consistently is not guaranteed.

    JD> And if you want to keep working as a developer, binding yourself
    JD> to a single language is probably not a good idea anyway (if only
    JD> because doing multiple interesting languages is a good way to
    JD> get better as a developer).

From a professional point of view, though, I think you have to have some
level of specialization.  You can't be equally good at everything, and
so you need to choose an area to focus on.  In my case, I've focused on
Perl and open source technologies to the almost complete exclusion of
Java, mainly because I found that the slightest hint of Java on my
resume got me attention from a lot of recruiters pushing jobs that I had
no interest in.

Charlton





-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: 7 Jul 2008 13:31:27 GMT
From: greymaus <greymausg@mail.com>
Subject: Re: Generating fancy/pretty documents
Message-Id: <slrng745ug.91r.greymausg@maus.org>

On 2008-07-06, Bernie Cosell <bernie@fantasyfarm.com> wrote:
> Joost Diepenmaat <joost@zeekat.nl> wrote:
>
> } Bernie Cosell <bernie@fantasyfarm.com> writes:
> } > etc were all relatively easy.  Is that kind of thing easy/reasonable to do
> } > with one of the "direct to PDF" packages?  ...
> } 
> } My experience with HTML -> PDF translators is that it's too easy to
> } generate some HTML that won't get translated correctly, and you can
> } usually forget about generating references to sections with page
> } numbers and things like that.
>
> Just so.  I can only say two things to this [on the mark] comment: first is
> that for some of what I want to do that's likely to be OK.  Note that since
> I'll be generating the HTML *with*Perl*, I have a lot of control over not
> generating things that HTMLDOC won't translate properly (NB: I *have* used
> this approach in the past and it worked quite well.)   Second, it is easy
> to "proof" the output (indeed, in the past when I've gone this route, I
> wrote my Perl stuff as CGI pgms, rather than standalone pgms, and it was
> remarkably simple to get everything debugged with just a few mouse-clicks
> in the browser).  But you're right: even when everything was perfect, I
> needed to [and did] play around with the HTML I generated to produce
> something that HTMLDOC did the "right thing" with.  And the best I can say
> is that the PDFs were "OK" [basically, looking like unadorned text web
> pages].
>
> So thanks for the pointer: time to go re-learn LaTeX and see how it goes...

My 2 cents worth.. Consider perls write function, if the data _Can_ be
structured that way. Simpler that going through Tex?Latex. Then, if you
want it to look well , pump it through `enscript'.

-- 
Greymaus
 .
  .
 ...  


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

Date: Mon, 7 Jul 2008 17:47:22 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Generating fancy/pretty documents
Message-Id: <slrng74eka.btd.hjp-usenet2@hrunkner.hjp.at>

On 2008-07-07 13:31, greymaus <greymausg@mail.com> wrote:
> On 2008-07-06, Bernie Cosell <bernie@fantasyfarm.com> wrote:
[...]
>> So thanks for the pointer: time to go re-learn LaTeX and see how it goes...
>
> My 2 cents worth.. Consider perls write function, if the data _Can_ be
> structured that way. Simpler that going through Tex?Latex. Then, if you
> want it to look well , pump it through `enscript'.
>

I suspect your definition of "look well" differs from Bernie's.

	hp


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

Date: Mon, 7 Jul 2008 01:10:15 -0700 (PDT)
From: "dev_kr_banga@hotmail.com" <dev.b.85@gmail.com>
Subject: session
Message-Id: <59095995-ea6b-4683-b130-3a3c3c648096@f36g2000hsa.googlegroups.com>

i m had made a web page and now i want to set session on it.....

please can any body tell me how to set seesion on my web page


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

Date: Mon, 7 Jul 2008 01:32:18 -0700 (PDT)
From: "dev_kr_banga@hotmail.com" <dev.b.85@gmail.com>
Subject: session
Message-Id: <84c0323c-4c1f-4622-a0ff-56df00d6ba7b@c58g2000hsc.googlegroups.com>

i  had made a web page and now i want to set session on it.....

please can any body tell me how to set seesion on my web page


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

Date: Mon, 7 Jul 2008 07:44:59 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: session
Message-Id: <da3e2305-bcc1-4c86-988d-af606038192a@y38g2000hsy.googlegroups.com>

On Jul 7, 1:10 am, "dev_kr_ba...@hotmail.com" <dev.b...@gmail.com>
wrote:
> i m had made a web page and now i want to set session on it.....
>
> please can any body tell me how to set seesion on my web page

http://search.cpan.org/~markstos/CGI-Session-4.32/lib/CGI/Session.pm
http://search.cpan.org/~markstos/CGI-Session-4.32/lib/CGI/Session/Tutorial.pm


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

Date: Mon, 07 Jul 2008 12:12:17 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: session
Message-Id: <m1lk0dn066.fsf@dot-app.org>

"dev_kr_banga@hotmail.com" <dev.b.85@gmail.com> writes:

> i  had made a web page and now i want to set session on it.....
>
> please can any body tell me how to set seesion on my web page

Options abound, and depend a great deal on what framework (if any) you
are using. A "behind the scenes" description of HTTP "sessions" can be
found here: 

<http://jan.newmarch.name/ecommerce/session.html>

If you're writing a simple standalone CGI, you might have a look at
the CGI::Session module:

<http://search.cpan.org/~markstos/CGI-Session-4.32/lib/CGI/Session.pm>

But, if you're using an application framework such as Catalyst,
session support is usually already included in the framework:

<http://search.cpan.org/~nuffin/Catalyst-Plugin-Session-0.19/lib/Catalyst/Plugin/Session.pm>

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Mon, 07 Jul 2008 15:24:29 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Value of "Programming perl" 1st Ed.?
Message-Id: <m1abgtbiqa.fsf@dot-app.org>

Anyone know if a 1st edition Camel in very good condition would have
any appeal to collectors, and if so, what its value might be?

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Mon, 7 Jul 2008 07:40:08 -0700 (PDT)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Want regex s/// to replace only nth occurrence
Message-Id: <13cad477-9c2a-4f60-a157-7516e897ed8f@2g2000hsn.googlegroups.com>

On Jul 6, 9:17=A0am, jerrykrin...@gmail.com wrote:
> my $s =3D "The sneaky cat sneaked sneakily." ;
>
> I would like a simple s/// statement which would replace only the $nth
> occurrence of "sneak". =A0 ($n is a variable). =A0Can't find the answer.
> Is this possible?

I'm confused by all the complex answers.  Why not something as simple
as this?

my $s =3D "The sneaky cat sneaked sneakily";
my $n =3D 3;
my $r =3D $n - 1;
$s =3D~ s/((?:sneak.*?){$r})sneak/${1}angr/;


Seems to work fine for $n =3D 1, 2, and 3 in my tests.

Paul Lalli


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

Date: Mon, 7 Jul 2008 18:41:50 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Want regex s/// to replace only nth occurrence
Message-Id: <slrng74hqf.btd.hjp-usenet2@hrunkner.hjp.at>

On 2008-07-06 21:39, jerrykrinock@gmail.com <jerrykrinock@gmail.com> wrote:
> Gunnar's solution I was able to understand and modify to do what I
> really wanted to do, which is, in DBI database queries, to replace "
>= ? " with "IS NULL" when placeholders are undef.  This problem is
> described in http://search.cpan.org/~timb/DBI-1.605/DBI.pm#Placeholders_and_Bind_Values,
> in the subsection "Null Values", but that document doesn't give a
> function to test the whole values array and query after construction,

I think it does:

| The following technique illustrates qualifying a WHERE clause with
| several columns, whose associated values (defined or undef) are in a
| hash %h:
| 
|   for my $col ("age", "phone", "email") {
|     if (defined $h{$col}) {
|       push @sql_qual, "$col = ?";
|       push @sql_bind, $h{$col};
|     }
|     else {
|       push @sql_qual, "$col IS NULL";
|     }
|   }
|   $sql_clause = join(" AND ", @sql_qual);
|   $sth = $dbh->prepare(qq{
|       SELECT fullname FROM people WHERE $sql_clause
|   });
|   $sth->execute(@sql_bind);


> which I could call at a low level in my code to avoid having to
> remember to do this all the time.  I now have such a function,
> explicifyNullsInRefs, shown below.
>
> Thanks for the help!
>
> P.S.  There are probably still bugs in this code.  Also, probably
> someone will point me at a function in a CPAN module that already does
> this.  Oh, well.
>
> #!/usr/bin/perl
>
> # Problem: A query to find names of all small,
> #        healthy, 3-year old, albino, fast pets
>
> # Demo Code
> my $query = q{SELECT name FROM pets
>     WHERE
>         size = ? AND disease   = ? AND 'age' = ? and `color`=? and

Note that 'age' = 3 is never true ('age' is a string literal, not a
column name). I assume you mean age without quotes. (`color` is ok, but
non-portable). 

> speed>?} ;

Having different operators (">" and "=") makes it a bit more
complicated, but one could replace the values of the hash with
[ operator, value ] tuples, like this:

> my @values = ("small", undef, 3, undef, 66) ;

# untested code fragment follows:
sub print_pet_names {
    my ($dbh, $query) = @_;

    for my $col (keys %$query) {
      if (defined $query{$col}[1]) {
        push @sql_qual, "$col " . $query{$col}[0] . " ?";
        push @sql_bind, $h{$col};
      }
      else {
	if ($query{$col}[0] eq '=') {
	    push @sql_qual, "$col IS NULL";
	} else {
	    push @sql_qual, "$col IS NOT NULL";
	}
      }
    }
    $sql_clause = join(" AND ", @sql_qual);
    $sth = $dbh->prepare(qq{
        SELECT name FROM pets WHERE $sql_clause
    });
    $sth->execute(@sql_bind);
    while (my ($name) = $sth->fetchrow_array) {
	print "$name\n";
    }
}

print_pet_names($dbh,
                { size    => [ '=', 'small' ],
		  disease => [ '=', undef ],
                  age     => [ '=', 3 ],
                  color   => [ '=', undef ],
		  speed   => [ '>', 66 ],
		 });

or something similar.

	hp


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

Date: Mon, 07 Jul 2008 21:44:41 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Want regex s/// to replace only nth occurrence
Message-Id: <g4trna$2301$1@nserver.hrz.tu-freiberg.de>

Paul Lalli wrote:
> I'm confused by all the complex answers.  Why not something as simple
> as this?
> 
> my $s = "The sneaky cat sneaked sneakily";
> my $n = 3;
> my $r = $n - 1;
> $s =~ s/((?:sneak.*?){$r})sneak/${1}angr/;
> 
> Seems to work fine for $n = 1, 2, and 3 in my tests.

It should work fine until $n = 32765.

BTW yours is faster than I thought:


use strict;
use warnings;
use Benchmark qw(cmpthese);

my $nnn = 10_000 * 3;
my $str = "The sneaky cat sneaked sneakily. hehehe! " x 10_000;


cmpthese(
  -1, {
        'n-1 Quantifier (Lalli)' => sub {
             my ($s, $n) = ($str, $nnn-1);
             $s =~ s/((?:sneak.*?){$n})sneak/${1}angr/;
         },
         'Dynamic Regex (Wahab)' => sub {
             my $s=$str; our $n=$nnn;
             $s =~ s/(?>sneak(??{--$n?'(?!)':''}))/angr/;
         },
       }
);



Regards

Mirco



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

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 V11 Issue 1697
***************************************


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