[22711] in Perl-Users-Digest
Perl-Users Digest, Issue: 4932 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 4 09:05:47 2003
Date: Sun, 4 May 2003 06:05:07 -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, 4 May 2003 Volume: 10 Number: 4932
Today's topics:
Re: Checking administrator rights (Gert Vanderstukken)
Re: code optimization and readability (Mark Jason Dominus)
Re: code optimization and readability <bob@nowhere.com>
Re: code optimization and readability <nas@ANTISPAMnasland.nu>
Re: code optimization and readability <dmcbride@naboo.to.org.no.spam.for.me>
Re: Compare Lists - built in Function? <REMOVEsdnCAPS@comcast.net>
Re: Compare Lists - built in Function? pa@invalid.invalid
Re: Compare Lists - built in Function? <bigj@kamelfreund.de>
Re: Compare Lists - built in Function? <w.koenig@acm.org>
Re: Compare Lists - built in Function? <noreply@gunnar.cc>
downloading a page <samj@austarmetro.com.au>
Re: Forms structure <samj@austarmetro.com.au>
Re: Is there any way to debug PerlScript used in ASP? <denshimeiru-sapmctacher@durchnull.ath.cx>
no speed differences with mod_perl? <ntnewsNOSPAM@hrz3.hrz.tu-darmstadt.de>
Re: one liner in command line <you.gotta.be@kidding.com>
Re: Perl Editor : Whats Recommended <bigj@kamelfreund.de>
Sort array of numbers <motis@lyciumnetworks.com>
Re: Sort array of numbers <fxn@hashref.com>
Re: Sort array of numbers (Sam Holden)
Re: Sort array of numbers <motis@lyciumnetworks.com>
Re: Sort array of numbers <":-)"@hotmail.com>
Store Perl Functions in a DB? <abuse@mweb.co.za>
Re: Store Perl Functions in a DB? <tassilo.parseval@rwth-aachen.de>
Re: string checking, before using in SENDMAIL -> 'één' <tunmaster@hotmail.com>
Re: uniquifying and accumulating <bigj@kamelfreund.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 May 2003 01:02:56 -0700
From: gert.vanderstukken@pandora.be (Gert Vanderstukken)
Subject: Re: Checking administrator rights
Message-Id: <5eb4ae79.0305040002.5dd7cdcd@posting.google.com>
Clay Irving <clay@panix.com> wrote in message news:<slrnbb8cp9.qhv.clay@panix3.panix.com>...
> In article <5eb4ae79.0305031214.54ed6e9f@posting.google.com>,
> Gert Vanderstukken wrote:
>
> > I'm looking for a way to check if the script is ran under an
> > administrative account, but I cannot seem to find it.
>
> perldoc perlvar
I'm sorry, but I cannot find the parameter to use. I'm using perl on a
Windows NT system.
------------------------------
Date: Sat, 3 May 2003 23:29:32 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: code optimization and readability
Message-Id: <b91jcs$r6$1@plover.com>
In article <xfVsa.258218$vs.21302624@news3.calgary.shaw.ca>,
Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> wrote:
>For example, H::T can use shared memory to store pre-parsed
>templates, or a file cache of them. T::T probably does something
>similar.
Nope, nothing like that. Premature optimization is the root of all
evil, and T::T is already fast.
One thing people often suggest is that T::T should take the code
fragments in the template and compile them into anonymous subroutines,
then call the anonymous subroutines, instead of using 'eval' every
time. There's even a module on CPAN, with the rather obnoxious name
'Text::FastTemplate', which does this. It seemed like a reasonable
thing to try, so I did some benchmarking, and found that it was indeed
sometimes faster than Text::Template---and often it was much slower.
If anyone with a real application finds that T::T is too slow and
wants to put in some work profiling it and make some recommendations,
I'd be really interested to see them. But my experience with
'optimizations' is that if you don't make this large time investment,
you end up with something like Text::FastTemplate that promises to be
faster and isn't.
In the meantime, I haven't had any complaints, so I've left it alone.
Incidentally, I released V1.44 last week, which has some minor bug
fixes, test suite enhancements, and documentation improvements.
------------------------------
Date: Sat, 03 May 2003 18:52:26 -0500
From: bob <bob@nowhere.com>
Subject: Re: code optimization and readability
Message-Id: <3eb4562c$1_1@127.0.0.1>
On Sat, 03 May 2003 13:43:52 -0500, Chris H. wrote:
> i decided that the direction i was going wasn't exactly optimized for
> several thousand hits/day (if i ever got that much). so i started a line
> by line "audit" of the code. using some tips from the good ol' camel
> book i proceeded to go through the scripts line by line seeing if i
> could write this line better or more efficient, or that block could be
> minimized to execute faster.
If performanc does becomes an issue, use mod_perl
(http://perl.apache.org). This allows your script to be compiled once per
httpd process, instead of each time it's called by a user clicking on it,
dramtically decreasing runtime and CPU use. From looking at your script,
it is neither a mod_perl module nor an Apache::Registry script. Some
modifications will be needed to run under mod_perl. Mods needed for
running under Apache::Registry are typcially less. In any event it can
increas server performance many times.
Also, note that several thousand hits a day is not that much. Example:
8000 hits per day over an 8 hour day is 1/3 hit per second.
That being the case it is far more important to produce good maintainable
code than to try and inline things that modularity demands should be
left as functions.
So, the previous poster's suggestions about using avalable modules to
improve and simplify your code make sense. Combined with mod_perl, your
code can be better AND faster.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
------------------------------
Date: Sun, 04 May 2003 00:49:27 GMT
From: "Chris H." <nas@ANTISPAMnasland.nu>
Subject: Re: code optimization and readability
Message-Id: <rsZsa.15944$g41.1176675@news1.east.cox.net>
thanks for all the tips guys, will be checking into it.
bob, sorry, i did forget to mention that this is running under mod_perl
already. its running via Apache::PerlRun instead of Registry. there is no
handler setup as they are all individual scripts, instead of being a main
module with various utility scripts. so while i may be getting some
benefit, im not getting it all. the next incarnation of this site will be
done under mod_perl properly.
thanks again
-chris h
bob wrote:
>
> If performanc does becomes an issue, use mod_perl
> (http://perl.apache.org). This allows your script to be compiled once per
> httpd process, instead of each time it's called by a user clicking on it,
> dramtically decreasing runtime and CPU use. From looking at your script,
> it is neither a mod_perl module nor an Apache::Registry script. Some
> modifications will be needed to run under mod_perl. Mods needed for
> running under Apache::Registry are typcially less. In any event it can
> increas server performance many times.
>
> Also, note that several thousand hits a day is not that much. Example:
> 8000 hits per day over an 8 hour day is 1/3 hit per second.
>
> That being the case it is far more important to produce good maintainable
> code than to try and inline things that modularity demands should be
> left as functions.
>
> So, the previous poster's suggestions about using avalable modules to
> improve and simplify your code make sense. Combined with mod_perl, your
> code can be better AND faster.
------------------------------
Date: Sun, 04 May 2003 02:14:00 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: code optimization and readability
Message-Id: <IH_sa.113244$ja.4198623@news2.calgary.shaw.ca>
Mark Jason Dominus wrote:
> In article <xfVsa.258218$vs.21302624@news3.calgary.shaw.ca>,
> Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> wrote:
>>For example, H::T can use shared memory to store pre-parsed
>>templates, or a file cache of them. T::T probably does something
>>similar.
>
> Nope, nothing like that. Premature optimization is the root of all
> evil, and T::T is already fast.
Fair enough. All my point was is that by letting someone else worry about
it, your code gets more maintainable. And you can get speed benefits
simply by upgrading. For example, an older version of CGI::Application
used a number of eval's where they weren't required. I actually helped the
C::A author see this (and provided benchmarks to prove it), and anyone who
upgraded automatically got this speed boost.
If someone gave you a patch that provided T::T a 5% improvement in speed
without any significant degradation to readability, would you not take the
patch? The OP, if he used T::T, would be able to upgrade and get that 5%
boost without any real effort - it's an effort someone else has expended
already. Rather than reinventing that wheel, including its optimisations.
> One thing people often suggest is that T::T should take the code
> fragments in the template and compile them into anonymous subroutines,
> then call the anonymous subroutines, instead of using 'eval' every
> time. There's even a module on CPAN, with the rather obnoxious name
> 'Text::FastTemplate', which does this. It seemed like a reasonable
> thing to try, so I did some benchmarking, and found that it was indeed
> sometimes faster than Text::Template---and often it was much slower.
I like the way that H::T precompiles the HTML text, and then caches that
precompiled version in memory in such a way that multiple processes can
take advantage of it (shared memory or disk cache).
That said, if I were to use T::T (which I'm considering), it wouldn't be for
HTML stuff anyway, so that type of caching would not be important to me.
In fact, the less steps between template and output, the better for that
application.
> If anyone with a real application finds that T::T is too slow and
> wants to put in some work profiling it and make some recommendations,
> I'd be really interested to see them. But my experience with
> 'optimizations' is that if you don't make this large time investment,
> you end up with something like Text::FastTemplate that promises to be
> faster and isn't.
>
> In the meantime, I haven't had any complaints, so I've left it alone.
Isn't that the idea of reusable code? Solve it once, and, barring a better
solution, leave well enough alone. :-)
> Incidentally, I released V1.44 last week, which has some minor bug
> fixes, test suite enhancements, and documentation improvements.
------------------------------
Date: Sat, 03 May 2003 19:31:01 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Compare Lists - built in Function?
Message-Id: <Xns9370D0A432AB2sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news:b91458$ep6v0$1@ID-184292.news.dfncis.de:
> news.chello.at wrote:
>> Is there any builtin function which does a compare of two sorted
>> lists? I only need true for 2 lists with the same values.
>
> Maybe you could compare two interpolated arrays:
>
> if ("@list1" eq "@list2") {
> print 'Identical lists';
> } else {
> print 'Not identical lists';
> }
my @list1 = ('first ', 'second');
my @list2 = ('first', ' second');
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+tF8oY96i4h5M0egRAk+fAJ9h7LxvnKEAw071j17X3dOiCxM3jQCgj9hm
brh2mK1qrNoBLLC7UsqIDDs=
=3cQ9
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 3 May 2003 16:57:17 -0400
From: pa@invalid.invalid
Subject: Re: Compare Lists - built in Function?
Message-Id: <dfa19b.el2.ln@brick.verano.sba.ca.us>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Maybe you could compare two interpolated arrays:
> if ("@list1" eq "@list2") {
> print 'Identical lists';
> } else {
> print 'Not identical lists';
> }
my @list1= ('one', 'two', 'three', 'four');
my @list2= ('one two', 'three four');
------------------------------
Date: Sun, 04 May 2003 09:58:23 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Compare Lists - built in Function?
Message-Id: <pan.2003.05.04.07.58.20.718584@kamelfreund.de>
news.chello.at wrote at Sat, 03 May 2003 18:14:20 +0000:
> Is there any builtin function which does a compare of two sorted lists? I
> only need true for 2 lists with the same values.
Not really.
But there are some CPAN modules, e.g.
Data::Compare
List::Compare
Array::Compare
Greetings,
Janek
------------------------------
Date: Sat, 03 May 2003 22:45:28 +0200
From: Winfried Koenig <w.koenig@acm.org>
Subject: Re: Compare Lists - built in Function?
Message-Id: <3EB42A68.2050705@acm.org>
Gunnar Hjalmarsson wrote:
>
> If I modify my suggestion to:
>
> if ("@list1" eq "@list2" and @list1 == @list2) {
> print 'Identical lists';
> } else {
> print 'Not identical lists';
> }
>
> I'd say that it does effectively the same thing as the first FAQ
> example. Comments?
Hmm, try this with:
$" = ' '; # the default
my @list1 = ('aa bb', 'cc');
my @list2 = ('aa', 'bb cc');
Winfried Koenig
------------------------------
Date: Sun, 04 May 2003 12:22:08 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b92ppg$etpd9$1@ID-184292.news.dfncis.de>
Winfried Koenig wrote:
> Gunnar Hjalmarsson wrote:
>> If I modify my suggestion to:
>>
>> if ("@list1" eq "@list2" and @list1 == @list2) {
>> print 'Identical lists';
>> } else {
>> print 'Not identical lists';
>> }
>>
>> I'd say that it does effectively the same thing as the first FAQ
>> example. Comments?
>
> Hmm, try this with:
>
> $" = ' '; # the default
> my @list1 = ('aa bb', 'cc');
> my @list2 = ('aa', 'bb cc');
Eric J. Roode wrote:
> my @list1 = ('first ', 'second');
> my @list2 = ('first', ' second');
Please, guys, I _have_ given it up. ;-)
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 04 May 2003 08:41:32 GMT
From: "Sam Jesse" <samj@austarmetro.com.au>
Subject: downloading a page
Message-Id: <3eb4d23a@news.comindico.com.au>
I am not getting the page from the address yahoo.com as a $res. even thoug I
am not up to that level where I can understand every line of the code below.
I copied it from the LWP module documentations. I get Bad Luck this time
printed.
Thanks
Sam
#!/perl -w
use strict;
# Create a user agent object
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 "); # Create a request
my $req = HTTP::Request->new(POST => 'http://www.yahoo.com');
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0'); # Pass request to the user agent and
get a response back
my $res = $ua->request($req); # Check the outcome of the response
if ($res->is_success) {
print $res->content;
} else {
print "Bad luck this time\n";
}
------------------------------
Date: Sun, 04 May 2003 07:00:25 GMT
From: "Sam Jesse" <samj@austarmetro.com.au>
Subject: Re: Forms structure
Message-Id: <3eb4ba88@news.comindico.com.au>
thanks alot for all the post. I learned alot.. greatly appriciated
Sam
"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.53.0305031711050.31909@lxplus087.cern.ch...
> On Sat, May 3, Andrew Lee inscribed on the eternal scroll:
>
> > On Fri, 2 May 2003 23:55:17 +0200, "Alan J. Flavell"
> > <flavell@mail.cern.ch> wrote:
> >
> > >CGI programs are written in a wide range of languages (I've seen
> > >perfectly serious discussions of CGI programs written in COBOL, for
> > >example).
> >
> > I never said cgi's weren't written in other languages ...
>
> I'm sorry, I hadn't intended to imply that _you_ didn't know that: my
> remark was really aimed at the gallery, considering that this group
> often gets irritated by newbies who think that Perl exists only for
> writing CGI scripts and that CGI scripts can only be written in Perl:
> I had no doubt that you were aware than neither of these is true, but
> somehow, in composing my response "on the hoof" I didn't make my
> meaning very clear.
>
> Cheers
>
> --
>
> The difficulty arises because the kind of people who can sell to
> your powers-that-be are incompatible with those of us with a clue
> on technical subjects. - Nick Kew on c.i.w.a.stylesheets
------------------------------
Date: 3 May 2003 23:14:29 GMT
From: Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx>
Subject: Re: Is there any way to debug PerlScript used in ASP?
Message-Id: <slrnbb8jb1.cmn.denshimeiru-sapmctacher@message-id.durchnull.ath.cx>
Scripsit iste aut ista »Andrew« <45724remove@yahoo.com>:
> Thanks Rudolf, but I still hope there's a debugger...
Can you perhaps use Perl's integrated debugger? No idea how it's
interpreted in ASP...
--
So long and thanks for all the fish.
------------------------------
Date: Sun, 4 May 2003 14:06:31 +0200
From: "alex" <ntnewsNOSPAM@hrz3.hrz.tu-darmstadt.de>
Subject: no speed differences with mod_perl?
Message-Id: <b92vo8$1db$02$1@news.t-online.com>
hi
i have installed the "theoryx5.uwinnipeg.ca" - Perl 5.8/Apache2/mod_perl
1.99-10 distribution - but after all configured and the startup.pl changes
with "use DBI" and "use DBD-ODBC" i cannot see any speed differences as
without mod_perl... whats wrong? i thought mod_perl is about 20-30 times
faster and is caching the DB connections... but it looks very slow.
Benchmark gives me same times as without mod_perl. i haven't changed
anything inside the perl scripts - could i change something?
Alex
------------------------------
Date: Sat, 03 May 2003 18:21:51 -0700
From: Michael Eric Battle <you.gotta.be@kidding.com>
Subject: Re: one liner in command line
Message-Id: <3EB46B2F.6780FC05@kidding.com>
Graham Drabble wrote:
> On 17 Feb 2003 Josef Möllers <josef.moellers@fujitsu-siemens.com>
> > nobody wrote:
> >> > how can use a variable in a one line program
> >> > if it's in the command line?
> >> perl -e "my $x=99; print $x;"
> >
> > Not really:
> >
> > josef@bounty:~ > perl -e "my $x=99; print $x;"
> > syntax error at -e line 1, near "my ="
> > Execution of -e aborted due to compilation errors.
>
> C:\>perl -e "my $x=99; print $x;"
> 99
> C:\>
>
> > Better:
> > perl -e 'my $x=99; print $x;'
>
> C:\>perl -e 'my $x=99; print $x;'
> Can't find string terminator "'" anywhere before EOF at -e line 1.
>
> I think this is a Windows/Unix thing.
Maybe.
Maybe you're better off with the single quotes.
The double quotes interpolate (at the shell level)
for shell escape characters like \ and $ so you have
to do:
perl -e "my \$x = 99; print \$x"
which works for me but lacks a trailing newline.
Adding the newline requires a heartstopping number
of backslashes:
mikie@thoras:~> perl -e "my \$x = 99; print \"\$x\n\""
99
These go away if you use single quotes in the outlying
string, which don't do any interolation except for \:
mikie@thoras:~> perl -e 'my $x = 99; print "$x\n"'
99
If those don't work in the Empire,
it's Bill Gates' fault.
MikEB
--
(O<
//\
V_V
------------------------------
Date: Sun, 04 May 2003 10:17:17 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Perl Editor : Whats Recommended
Message-Id: <pan.2003.05.04.08.15.51.202027@kamelfreund.de>
Rudolf Polzer wrote at Sat, 03 May 2003 10:43:34 +0000:
> vi doesn't have that feature, but something else which might be good in those
> cases:
>
> You see:
>
> # ...
> }
> else
> {
> # ...
> }
>
> Move over the closing brace before the else and press %. You will be
> near the matching if.
And in addition, the moving to the next brace is simple:
to get the preceding opining {,
press [{ in normal mode
and to move to the next closing },
press ]}.
Another interesting feature can be done in visual mode (type v to get in)
With a{ you select everything of the current { ... } block.
(You can also use i{ instead of a{) to only select the intereor of the
{ ... } block but without the braces.
Greetings,
Janek
PS: I'm not sure whether vi has these features, but vim has.
------------------------------
Date: Sun, 4 May 2003 12:07:12 +0200
From: "012" <motis@lyciumnetworks.com>
Subject: Sort array of numbers
Message-Id: <3eb4d870@news.012.net.il>
Hi
I'm looking for a way to sort aray of numbers. When I use the regular sort I
get:
0 1 10 11 2 3 4 5 6 7 8 9
Is there a simple way to handle that?
Thanks
Moti
------------------------------
Date: Sun, 4 May 2003 09:30:58 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: Sort array of numbers
Message-Id: <b92mki$lkv$1@news.ya.com>
In article <3eb4d870@news.012.net.il>, 012 wrote:
: I'm looking for a way to sort aray of numbers. When I use the regular sort I
: get:
: 0 1 10 11 2 3 4 5 6 7 8 9
Do you know why?
: Is there a simple way to handle that?
Sure, look at the examples in perldoc -f sort.
-- fxn
------------------------------
Date: 4 May 2003 09:35:16 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Sort array of numbers
Message-Id: <slrnbb9nmk.fao.sholden@flexal.cs.usyd.edu.au>
On Sun, 4 May 2003 12:07:12 +0200, motis@lyciumnetworks.com wrote:
> Hi
> I'm looking for a way to sort aray of numbers. When I use the regular sort I
> get:
> 0 1 10 11 2 3 4 5 6 7 8 9
>
> Is there a simple way to handle that?
For goodness sake, it is one of the examples in the sort documentation.
perldoc -f sort
Is it that hard to read a couple of pages of documentation on the function
you are using, before you waste the time of thousands of people around
the world?
--
Sam Holden
------------------------------
Date: Sun, 4 May 2003 12:44:56 +0200
From: "012" <motis@lyciumnetworks.com>
Subject: Re: Sort array of numbers
Message-Id: <3eb4e14b@news.012.net.il>
Thanks, I didn't know about the perldoc option...
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnbb9nmk.fao.sholden@flexal.cs.usyd.edu.au...
> On Sun, 4 May 2003 12:07:12 +0200, motis@lyciumnetworks.com wrote:
> > Hi
> > I'm looking for a way to sort aray of numbers. When I use the regular
sort I
> > get:
> > 0 1 10 11 2 3 4 5 6 7 8 9
> >
> > Is there a simple way to handle that?
>
> For goodness sake, it is one of the examples in the sort documentation.
>
> perldoc -f sort
>
> Is it that hard to read a couple of pages of documentation on the function
> you are using, before you waste the time of thousands of people around
> the world?
>
> --
> Sam Holden
>
------------------------------
Date: Sun, 04 May 2003 21:53:09 +1000
From: ":-)" <":-)"@hotmail.com>
Subject: Re: Sort array of numbers
Message-Id: <3EB4FF25.63015F09@hotmail.com>
012 wrote:
>
> Hi
> I'm looking for a way to sort aray of numbers. When I use the regular sort I
> get:
> 0 1 10 11 2 3 4 5 6 7 8 9
>
> Is there a simple way to handle that?
> Thanks
> Moti
#!/bin/perl
use strict;
use warnings;
my @array=qw(7 1 10 11 2 5 4 3 6 0 8 9);
print("Before:\t@array\n");
@array=sort{$a<=>$b}@array;
print("After:\t@array\n");
------------------------------
Date: Sun, 04 May 2003 10:37:53 +0200
From: "Nico Coetzee" <abuse@mweb.co.za>
Subject: Store Perl Functions in a DB?
Message-Id: <pan.2003.05.04.08.37.52.776632@mweb.co.za>
Hi
Maybe I'm just crazy, but I was wondering if it would be possible to store
Perl functions in a DB Table. Can it work? If yes - how ( samples )?
Sometimes I think up crazy stuff - this is for pure fun :)
Cheers
--
Nico Coetzee
http://www.itfirms.co.za/
http://za.pm.org/
http://forums.databasejournal.com/
To the systems programmer, users and applications serve only to provide a
test load.
------------------------------
Date: 4 May 2003 10:57:11 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Store Perl Functions in a DB?
Message-Id: <b92rm7$llr$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Nico Coetzee:
> Maybe I'm just crazy, but I was wondering if it would be possible to store
> Perl functions in a DB Table. Can it work? If yes - how ( samples )?
You can use B::Deparse to turn a code-reference into a string that you
could store:
use B::Deparse;
sub func {
my $var = shift;
return $var * 2;
}
my $dep = B::Deparse->new;
my $source = $dep->coderef2text(\&func);
print $source;
__END__
{
my $var = shift @_;
return $var * 2;
}
You loose the name of the function, though, so if you want to turn it
back into executable code later you have to
*func = eval "sub $source";
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 03 May 2003 22:07:51 GMT
From: "joe" <tunmaster@hotmail.com>
Subject: Re: string checking, before using in SENDMAIL -> 'één' has to become 'een'
Message-Id: <X4Xsa.1190358$sj7.49142661@Flipper>
Wow, that certainly does the trick for me!
Vielen dank mein Freund!
Tjüsch!
> my %ascii = (qw(
> À A
> Á A
> Â A
> Ã A
> Ä Ae
> Å A
> Æ Ae
> )); # and so on
>
> and then a substitution
> $text =~ s/([$non_ascii_char])/$ascii{$1}/eg;
>
> where is
> $non_ascii_char = join "", map {chr} (128..255);
------------------------------
Date: Sun, 04 May 2003 10:17:20 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: uniquifying and accumulating
Message-Id: <pan.2003.05.04.08.07.53.390269@kamelfreund.de>
Julian Day wrote at Sat, 03 May 2003 10:24:58 -0700:
> Looking for an idiomatic (that is concise and perlish) way to flatten
> a list of names while accumulating associated values:
>
> Before:
>
> john:10
> john:2
> robert:15
> robert:20
> sally:4
>
> After:
>
> john:12
> robert:35
> sally:4
If the list is already sorted, you don't need a hash,
you can do it directly:
chomp( my ($last_name, $sum) = split /:/, scalar <DATA> );
while (<DATA>) {
chomp;
my ($name, $inc) = split /:/;
if ($last_name eq $name) {
$sum += $inc
} else {
print "$last_name:$sum\n";
($last_name, $sum) = ($name, $inc);
}
}
__DATA__
john:10
john:2
robert:15
robert:20
sally:4
There are sure some shorter ways,
but the principle should be clear.
Greetings,
Janek
------------------------------
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 4932
***************************************