[16930] in Perl-Users-Digest
Perl-Users Digest, Issue: 4342 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 16 14:05:27 2000
Date: Sat, 16 Sep 2000 11:05:11 -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: <969127510-v9-i4342@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 16 Sep 2000 Volume: 9 Number: 4342
Today's topics:
Re: Check DIR? <brian@ukdj.freeserve.co.uk>
how do I alphabetize this? <hshir@mediaone.net>
Re: How to use regular expression with GB code in Perl? <carfield@programmer.net>
lynx shows html-tags <pilsl@goldfisch.atat.at>
Re: lynx shows html-tags (Abigail)
Re: Module for CGI Session Management? (brian d foy)
Re: Newbie - windows directory location (Keith Calvert Ivey)
Re: Password protecting a script (brian d foy)
Re: Password protecting a script <flavell@mail.cern.ch>
Re: Qualifications for new Perl programmer????? (David H. Adler)
Re: Regexp: matching '|' <ren.maddox@tivoli.com>
Re: Regular Expression for matching with email addresse (brian d foy)
Re: Regular Expression for matching with email addresse <mbudash@sonic.net>
Re: Regular Expression for matching with email addresse <flavell@mail.cern.ch>
setproctitle analog in Perl <andrew@nextra.cz>
Re: Shortest code for Fibonacci? (Tramm Hudson)
Re: Shortest code for Fibonacci? (Mark-Jason Dominus)
Re: Shortest code for Fibonacci? <jeffp@crusoe.net>
Re: Shortest code for Fibonacci? <jeffp@crusoe.net>
Re: Shortest code for Fibonacci? <christopher_j@uswest.net>
Re: Shortest code for Fibonacci? (Abigail)
sql 7 maintenance script <bill@billcampbell.com>
TEST <crud_alex@yahoo.com>
Re: tutorial for advanced experimental regex features? <ren.maddox@tivoli.com>
Re: tutorial for advanced experimental regex features? <jeffp@crusoe.net>
Re: tutorial for advanced experimental regex features? <ren.maddox@tivoli.com>
Re: Variables <ren.maddox@tivoli.com>
Re: Variables <jeffp@crusoe.net>
Re: Variables <ren.maddox@tivoli.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 16 Sep 2000 14:51:41 +0100
From: "Brian" <brian@ukdj.freeserve.co.uk>
Subject: Re: Check DIR?
Message-Id: <8pvuep$qk7$1@newsg2.svr.pol.co.uk>
OK Thanks guys, all working now :)
Philip Garrett <philipg@atl.mediaone.net> wrote in message
news:1vEw5.3124$jC4.785113@typhoon.southeast.rr.com...
> Brian <brian@ukdj.freeserve.co.uk> wrote in message
> news:8pus46$nln$1@news8.svr.pol.co.uk...
> > Hi All
> >
> > I am trying to find our if a directory exists or not. below is the code
> but
> > doesn't work, any ideas?
> >
> > opendir (DIR,"photos/$dirname");
> > print "The DIR is photos/$dirname<BR>";
> > if (DIR) {
> > print "It's There";
> > $dirset=1
> > }
> > else {
> > print "OH God, who stole it?";
> > $dirset=0
> > }
>
> You're making this much too hard. All you need is the -d function.
>
> $dirset = -d "photos/$dirname";
>
> For more info, try 'perldoc perlfunc', and look for the heading "-X EXPR"
>
> hth,
> Philip
>
>
------------------------------
Date: Sat, 16 Sep 2000 17:26:10 GMT
From: "matthew shir" <hshir@mediaone.net>
Subject: how do I alphabetize this?
Message-Id: <S2Ow5.23907$pu4.2112716@typhoon.ne.mediaone.net>
I want the contents of a list to print out in alphabetical order.
Any ideas on how to do this? thanks!
------------------------------
Date: Sat, 16 Sep 2000 23:10:58 +0800
From: Carfield Yim <carfield@programmer.net>
Subject: Re: How to use regular expression with GB code in Perl?
Message-Id: <39C38D82.46775024@programmer.net>
Hi all, finally I find the solution, if anyone interested, you can take a
look:
http://rockey.iis.sinica.edu.tw/oliver/perl/perlc.html
Carfield Yim wrote:
> How to use regular expression with GB code in Perl? After I wrote my
> application, I find that the program always show:
> Malformed UTF-8 character at count_freq.pl line 32, <DATA_FILE> line 5.
>
> How can I solve??
>
> I think that the problem is GB code is 16 bit but not 8 bit. However, how
> to use UTF 16 is perl??
------------------------------
Date: Sat, 16 Sep 2000 15:36:23 GMT
From: peter pilsl <pilsl@goldfisch.atat.at>
Subject: lynx shows html-tags
Message-Id: <MPG.142d9c83110d0b27989888@news.chello.at>
I just ran into the following problem and it took me quite a while until I
solved it. I just entered a question-posting when the solution came into
my mind and so I post just the solution if someone has the same problem
some day ... ;)
The output of my cgi-script was very nice in all the tested GUI-browsers
(ie,netscape,opera) but lynx refused to show more than the pure html-code.
solution: if you make any output before printing the header (a small
error-output in my case) you want see this output in all the tolerant gui-
browsers, but it will confuse lynx ....
peter "when will I sleep again"-databaseinterfacecriminal ...
--
pilsl@
goldfisch.at
------------------------------
Date: 16 Sep 2000 16:30:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: lynx shows html-tags
Message-Id: <slrn8s77ua.4mc.abigail@alexandra.foad.org>
peter pilsl (pilsl@goldfisch.atat.at) wrote on MMDLXXIII September
MCMXCIII in <URL:news:MPG.142d9c83110d0b27989888@news.chello.at>:
@@
@@ I just ran into the following problem and it took me quite a while until I
@@ solved it. I just entered a question-posting when the solution came into
@@ my mind and so I post just the solution if someone has the same problem
@@ some day ... ;)
@@
@@ The output of my cgi-script was very nice in all the tested GUI-browsers
@@ (ie,netscape,opera) but lynx refused to show more than the pure html-code.
@@
@@ solution: if you make any output before printing the header (a small
@@ error-output in my case) you want see this output in all the tolerant gui-
@@ browsers, but it will confuse lynx ....
Well, beside the fact that lynx is the only one to handle this issue
correctly (and not as you might thing the GUI b0rken browsers, written
by people who can't code their way out of a paper bag), what has this
to do with Perl?
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Sat, 16 Sep 2000 12:56:49 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Module for CGI Session Management?
Message-Id: <brian-ya02408000R1609001256490001@news.panix.com>
In article <39C2DEAE.FAA9DFA5@shentel.net>, Albert Dewey <timewarp@shentel.net> posted:
> I made my own routines to do precisely this. I generate a session number upon the
> user entering the site using rand( ) and put this value into a cookie.
this sounds like there could be a chance for non-unique session
numbers. you should be using a lot more than just rand(), which isn't
really random.
> I also
> store this same number, as well as a number of other factors, in a data file and
> when the user navigates the site, I retrieve his cookie and compare it with his
> session entry in the datafile and act accordingly. Then I use crontab once every
> 24 hours to clean up old sessions based on their time of creation. Really quite
> simple to setup and manage.
if sessions stay around longer than they should, then you have a
security problem, especially if your session numbering is vunerable.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Sat, 16 Sep 2000 15:56:14 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Newbie - windows directory location
Message-Id: <39c396c0.3959066@news.newsguy.com>
"Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
wrote:
> use File::Basename;
> print dirname( $ENV{PATH_TRANSLATED} ); # dir your script is
>in
Not according to the CGI specification. I know Microsoft does
weird things with the CGI environment variables, so maybe that's
what you're talking about, but PATH_TRANSLATED is supposed to be
the file-system path corresponding to the extra path info. So
if you have
http://www.example.com/cgi-bin/script.pl/extra/stuff
then PATH_TRANSLATED is the path corresponding to
http://www.example.com/extra/stuff
It is not the directory where the script is.
To give this a modicum of Perl relevance, I'll mention that
this is in the CGI.pm documentation in the description of the
path_translated() function.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Sat, 16 Sep 2000 13:05:34 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Password protecting a script
Message-Id: <brian-ya02408000R1609001305340001@news.panix.com>
In article <39C2E6E2.8E708BFB@shentel.net>, Albert Dewey <timewarp@shentel.net> posted:
> This is really an Apache issue. You will have to generate a small file called
> .htaccess (the entire name is really a long file extension) with content
> similar to the following - (this file will live in the folder that you would
> like to password protect. If you are using more than one folder, you will have
> to create duplicate files inside each of these folders. A better way would be
> to group all the protected folders under a single protected folder and
> password protect just the one parent folder.)
>
> AuthUserFile /usr/local/mysite/htpasswd
> AuthGroupFile /dev/null
> AuthName MySite
> AuthType Basic
> <Limit GET PUT POST>
there is no need to use limit. indeed, the Apache docs explain
why this is a bad idea.
> require user admin
> require user joe
> require user steve
> </Limit>
>
> Then you will need to encrypt a password for the user and store the encrypted
> result in a file called htpasswd (no file extension) as such -
you can name the file whatever you like, as long as it is the same
file in AuthUserGroup.
> A sample of code I use (stripped down to just the essentials) to automate this
> process is as follows -
>
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
you send an HTTP header before you even know what you should
output. this makes error handling more difficult.
> use CGI qw/:standard/;
> $Password = param('password');
> $UserName = param('username');
>
> ## Create the new user
> &New_User;
all of this is much more easily done, and much more flexible,
with HTTPD::UserAdmin. this would also fix some of the errors.
> ## Write to the password file in encrypted form
> open(POST,">>/usr/local/mysite/htpasswd");
no file locking? this can be a problem.
> print POST ("$UsrPwdString\n");
> close(POST);
> ## Add the new user to the .htaccess file
> $new_entry = "require user $UserName";
there is no need to do this. in fact, it is silly. just use
require valid-user
no need for acrobatics.
> To any Perl Gods out there full of sharp comments and criticizms - I am aware
> that there are a number of ways to do this so try and keep your comments to
> presenting your own routine or pointing out glaring syntax errors in mine.
> The
> code I have here does work so it should be good enough as an example for Geoff
> to get started with.
perhaps you are satisfied with "good enough". others might not be.
it's too bad that you have so low regard for your post that you have
to give such a disclaimer.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Sat, 16 Sep 2000 19:41:55 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Password protecting a script
Message-Id: <Pine.GHP.4.21.0009161916000.22343-100000@hpplus03.cern.ch>
On Fri, 15 Sep 2000, Albert Dewey wrote:
(quotes entire posting including sig - the alarm bells are already
ringing...)
> <Limit GET PUT POST>
Please read the Apache documentation. Do not propagate this cargo
cult.
> require user admin
> require user joe
> require user steve
If you want to allow access by any user who can provide valid
credentials, then
require valid-user
would be a more appropriate form to use.
If you only want to allow a subset of users to enter, then this
would be a good reason to define a group, and to require that
instead.
> A sample of code I use (stripped down to just the essentials)
Server security is something to be taken seriously. You seem to be
missing several things which need to be considered "essentials".
Good to see you using CGI.pm, anyhow.
> ## Write to the password file in encrypted form
> open(POST,">>/usr/local/mysite/htpasswd");
> print POST ("$UsrPwdString\n");
> close(POST);
File locking, as well as testing for success, are "essentials": it's
really negligent - and I mean that in all seriousness - to offer
someone a solution which lacks them.
For this part of the game there are some useful techniques in Randals
WebTechniques
http://www.stonehenge.com/merlyn/WebTechniques/col05.listing.txt
(though nowadays the use of numerical constants in flock would be
deprecated, as he already commented here).
In fact, far from being "stripped down to its essentials", what you
offered here contained a great deal of trivial clutter and was, as I
say, _missing_ several vital essentials. As well as containing at
least one piece of bad cargo.
> print ("<center><br><b><u>New User Added</u></b><br><br>\n");
Your HTML is also execrable, though that's off-topic here.
> To any Perl Gods out there full of sharp comments and criticizms -
> I am aware that there are a number of ways to do this so try and
> keep your comments to presenting your own routine or pointing out
> glaring syntax errors in mine.
Look, this is a serious programming forum. If you can't take peer
review, then you'd be better just lurking. I would rather learn from
the Perl Gods, than want to erect fences before they've even spoken on
the topic.
------------------------------
Date: 16 Sep 2000 17:43:06 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <slrn8s7c9a.6uu.dha@panix6.panix.com>
On Fri, 15 Sep 2000 13:36:26 GMT, Brendon Caligari
<bcaligari@my-deja.com> wrote:
>it's true that with hashes and references just about any structure can
>be implemented, whilst with modules and class hashes. Perl
>takes 'away' the closeness between programmer and implementation. No
>strict types and checking, no real pointers, the richness of the
>language all risk the beginner become lazier and not appreciate the
>underlying foundations.
I think that depends on your method of teaching. Are you teaching the
underlying concepts? If so, it's less important what language you
use. I don't believe that you learn any better what a variable, a
function or a linked list is based on the language used in the
learning. [Note: we are talking in generalizations in this thread. I
certainly believe that it is possible that a given individual might
grasp these concepts better in one language over another.
Nevertheless, unless you're doing one-to-one teaching, and are willing
to take the time to decide what language works better for the
individual student, it's not particularly relevant here.] What matters
is that you actually teach the concepts. Yes, Perl allows you to
bypass a lot of implementation details - that does *not* mean you
*can't* use perl to explain those details.
>if you start teaching a beginner in perl.....would would he,
>say....know of sorting routines, lists, trees, graphs...
He would if you teach them to him/her/it. And, lookie here, there's
even a book about such things *in perl*... wow, how is *that*
possible??? :-)
Of course, all this assumes that the student in question isn't
impervious to learning in the first place...
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
* Nathan_Roberts screams out loud, "IS THIS ENTIRE CHANNEL COMPOSED
OF BOTS?!?!?"
<TheProf> Kill the human. - from the #drwhochat Quotefile
<http://www.crl.com/~nathanr/quote.html>
------------------------------
Date: 15 Sep 2000 21:19:34 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Regexp: matching '|'
Message-Id: <m3aed9cc3t.fsf@dhcp11-177.support.tivoli.com>
Mike Ayers <mayers@bmc.com> writes:
> I was preparing a pattern for use with Net::Telnet's waitfor(), which
> accepts a match pattern as an argument. Since I don't know how it
> handles the match pattern and need to match literal bars, I assumed the
> worst and tested my potential match patterns to work within bar
> delimiters. Probably not necessary, but safe.
Of course, if you are assuming the worst, you should consider that
other characters could be used as delimiters, such as "*". On the
other hand, it is really the responsibility of the module to handle
any special characters in the pattern you pass. Without evidence to
the contrary, I would expect that this module does, in which case you
have no need to worry.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Sat, 16 Sep 2000 12:52:31 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Regular Expression for matching with email addresses
Message-Id: <brian-ya02408000R1609001252310001@news.panix.com>
In article <39C2DC7A.AA48A18@shentel.net>, Albert Dewey <timewarp@shentel.net> posted:
> Try this - works for me -
>
> if ($Email =~ /[\w\-]+\@[\w\-]+\.[\w\-]+/)
> {
> Do stuff
> }
that doesn't work for all of the normal reasons. it doesn't even
come close to matching an RFC 822 address.
quit spreading the same old bad code.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Sat, 16 Sep 2000 09:53:19 -0700
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Regular Expression for matching with email addresses
Message-Id: <mbudash-EFCA4C.09531916092000@news.pacbell.net>
In article <39C2DC7A.AA48A18@shentel.net>, Albert Dewey
<timewarp@shentel.net> wrote:
> Rafael Garcia-Suarez wrote:
>
> > James Adams wrote in comp.lang.perl.misc:
> > >I want to verify that strings conform to a typical email address
> > >format. I have some code which can use Perl regular expressions as
> > >verification masks, but I'm not the world's best at Perl regular
> > >expressions so I'm hoping that someone can provide me with some example
> > >Perl regular expressions that I could use for this verification mask.
> > >
> > >I want to match with something like
> > >my.address_is-ugly@some.place.com (dashes, underscores, and digits are
> > >ok, only one @ sign, etc.)
> > >and fail to match with garbage such as this: bad%*)addres@isp@isp2.it
>
> Try this - works for me -
>
> if ($Email =~ /[\w\-]+\@[\w\-]+\.[\w\-]+/)
> {
> Do stuff
> }
>
> Albert Dewey
>
>
>
this is a faq... you can't do it easily... i use the Email::Valid perl
module...
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Sat, 16 Sep 2000 19:12:35 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Regular Expression for matching with email addresses
Message-Id: <Pine.GHP.4.21.0009161909140.22343-100000@hpplus03.cern.ch>
On Fri, 15 Sep 2000, Albert Dewey wrote:
> Try this
^^^^^^^^
Oh dear, and to an FAQ even. At least you used the magic formula
which translates to "usenet beware". I would have adjusted your score
accordingly - except that it's already on rock-bottom.
> - works for me -
Hmmm.
------------------------------
Date: Sat, 16 Sep 2000 15:59:23 +0200
From: Andrew Zhilenko <andrew@nextra.cz>
Subject: setproctitle analog in Perl
Message-Id: <39C37CBA.FEDE10A6@nextra.cz>
Hello!
How can change the name of my perl program (shown by ps)?
I want for example to get rid of "/usr/bin/perl" there.
In the BSD-flavored unixes exists setproctitle function,
but I do not know analog of it in SysV...
WBR, Andrew
--
Andrew Zhilenko, AZ283-RIPE, System Administrator
Nextra Czech Republic s.r.o.
tel.+42-02-96159436 fax. +42-02-96159422
e-mail: andrew@nextra.com http://www.nextra.cz
Vaclavske namesti 4 - Praha 1 - 110 00
Czech Republic
------------------------------
Date: 16 Sep 2000 14:40:12 GMT
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <8q00oc$4uj$1@sloth.swcp.com>
Abigail <abigail@foad.org> wrote:
() Tramm Hudson (hudson@swcp.com) wrote on MMDLXXII September MCMXCIII in
() `'
() `' How about a solution that is always O(1)?
() `'
() `' my ($Phi,$phi) = ( sqrt(5/4)-0.5, -sqrt(5/4)-0.5 );
() `' sub fib2 { return abs int(($Phi**$_[0] - $phi**$_[0])/sqrt(5)) }
()
() How do you raise powers in constant time?
On my slide rule. It always takes me the same length of time. Well,
not exactly. Sometimes the slide has to move further, causing the
total time to be slightly higher. Table look up on the computer would
accomplish the same thing. Up to MAXINT, of course.
You might as well ask, "How do you add in constant time?". Doesn't
it take longer to add two 2n bit number than two n bit ones?
Tramm
PS: On a related note, I can factor primes in constant time.
--
o hudson@swcp.com hudson@turbolabs.com O___|
/|\ http://www.swcp.com/~hudson/ H 505.323.38.81 /\ \_
<< KC5RNF @ N5YYF.NM.AMPR.ORG W 505.986.60.75 \ \/\_\
0 U \_ |
------------------------------
Date: Sat, 16 Sep 2000 14:50:47 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39c388c6.2d39$184@news.op.net>
In article <8q00oc$4uj$1@sloth.swcp.com>, Tramm Hudson <hudson@swcp.com> wrote:
>On my slide rule. It always takes me the same length of time.
I don't think so, because if you try to compute, say, 11**5 on your
slide rule, you're not going to get the right answer.
Anyone can compute the *wrong answer in constant time, and you don't
need a slide rule for that.
>You might as well ask, "How do you add in constant time?". Doesn't
>it take longer to add two 2n bit number than two n bit ones?
Yes, but at least you get the right answer!
------------------------------
Date: Sat, 16 Sep 2000 11:32:10 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <Pine.GSO.4.21.0009161131460.12023-100000@crusoe.crusoe.net>
On Sep 16, Tramm Hudson said:
>PS: On a related note, I can factor primes in constant time.
A damn long time, I assume. ;)
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Sat, 16 Sep 2000 11:34:25 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <Pine.GSO.4.21.0009161133210.12023-100000@crusoe.crusoe.net>
On Sep 16, Jeff Pinyan said:
>On Sep 16, Tramm Hudson said:
>
>>PS: On a related note, I can factor primes in constant time.
>
>A damn long time, I assume. ;)
Um, next time, I'll read the post before replying. I mis-thought (I'm not
sure what I thought you wrote).
I can factor primes in constant time too, when I've not misplaced my
brain.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Sat, 16 Sep 2000 09:10:49 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <bYMw5.129$yX3.87418@news.uswest.net>
"Bart Lateur" <bart.lateur@skynet.be> wrote:
> Clint Mario Cleetus wrote:
>
> >I am looking for a concise and elegant way to calculate the Fibonacci
> >Number corresponding to a given number. But it should also avoid
recursion
> >in order to be efficient.
>
> No need to avoid recursion. All you need to do is cache the results.
>
> See the Memoize module at CPAN. Fibonacci is even an example in the
> docs!
That's just plain nutty. It's a lot easier to use an explicit
formula for the fibonacci sequence. Plus, you can generate any
arbitrary number in the sequence really fast without having to
have generated all the previous ones.
------------------------------
Date: 16 Sep 2000 16:21:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8s77de.4mc.abigail@alexandra.foad.org>
Tramm Hudson (hudson@swcp.com) wrote on MMDLXXIII September MCMXCIII in
<URL:news:8q00oc$4uj$1@sloth.swcp.com>:
^^ Abigail <abigail@foad.org> wrote:
^^ () Tramm Hudson (hudson@swcp.com) wrote on MMDLXXII September MCMXCIII in
^^ () `'
^^ () `' How about a solution that is always O(1)?
^^ () `'
^^ () `' my ($Phi,$phi) = ( sqrt(5/4)-0.5, -sqrt(5/4)-0.5 );
^^ () `' sub fib2 { return abs int(($Phi**$_[0] - $phi**$_[0])/sqrt(5)) }
^^ ()
^^ () How do you raise powers in constant time?
^^
^^ On my slide rule. It always takes me the same length of time. Well,
^^ not exactly. Sometimes the slide has to move further, causing the
^^ total time to be slightly higher. Table look up on the computer would
^^ accomplish the same thing. Up to MAXINT, of course.
Let's see. Perl nowadays has 64 bit integers. That would require a
table with 2^128 entries, with a 4 byte double as entry, requiring
a measly 1237940039285380274899124224 Tb as storage. Not very
realistic.
Not that that is going to help you much as sqrt (5/4) ain't an integer.
^^ You might as well ask, "How do you add in constant time?". Doesn't
^^ it take longer to add two 2n bit number than two n bit ones?
No. Addition can be parallellized.
Abigail
--
CHECK {print "another "} # A tiger prowls beside
INIT {print "Perl " } # a river. A flying
BEGIN {print "Just " } # mosquito. Eshun.
END {print "Hacker\n"}
------------------------------
Date: Sat, 16 Sep 2000 13:20:59 GMT
From: "Bill" <bill@billcampbell.com>
Subject: sql 7 maintenance script
Message-Id: <%sKw5.190259$c5.4316110@news2.rdc1.on.home.com>
I have recently taken over the task of looking after a SQL 7 server (NT 4). The
"experts" have told me I should run the transaction dumps, db dumps and db
maintenance through a perl script in ISQL. Anyone agree ? And so that I don't
have to re-invent the wheel, where would I find an existing example ?
All help very much appreciated,
Regards,
Bill
bill@billcampbell.com
------------------------------
Date: Sun, 17 Sep 2000 01:15:25 +0800
From: "香港腳" <crud_alex@yahoo.com>
Subject: TEST
Message-Id: <8q09us$cvj$1@WWW1.relcom.ru>
--
即時戰略谷 : news://news.3home.net/3games.rts
for sc,aoe 同其他即時戰略迷
誠徵分版主中
-
我ICQ:29190749
[我至憎都市閒情同城市論壇咁既post]
-
如果死亡能剝奪一切的價值意義
那我們的生命就是賦予無法被剝奪的意義
------------------------------
Date: 15 Sep 2000 22:56:38 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: tutorial for advanced experimental regex features?
Message-Id: <m34s3hc7m1.fsf@dhcp11-177.support.tivoli.com>
Bart Lateur <bart.lateur@skynet.be> writes:
> I cannot make mluch sense of the advanced experimental regex features
> that are documented in perlre:
>
> (?{...})
> (?(cond)patyes|patno)
> (??{...})
>
> perlre is just a refrence manual, and that's precisely the problem. Does
> anybody have any idea on for example an online tutorial with lots of
> examples?
Can't help you there except to say that since these features are still
considered experimental, it is probably too soon form a tutorial.
> The feature I'd like to implement, is executing some Perl code at
> certain times in the matching process, which would optionally make the
> regex fail and backtrack, searching for alternatives. I just don't know
> where to start. I'm not yet even convinced it can be done.
It seems that the following idiom will do what you want:
perl -le '$_="one"; /(.*)(?(?{ $1 eq "one" })(?!))/; print $1'
Normally, $1 would be "one", but I am specifically causing a backtrack
in that situation, so $1 ends up as "on".
This combines (?(cond)patyes) with (?{...}) and (?!...). The two key
points are that a negative look-ahead for nothing always fails, and
the (cond) in a conditional pattern can be a (?{...}) code pattern.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Sat, 16 Sep 2000 10:48:47 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: tutorial for advanced experimental regex features?
Message-Id: <Pine.GSO.4.21.0009161048020.12100-100000@crusoe.crusoe.net>
[posted & mailed]
On Sep 15, Ren Maddox said:
>perl -le '$_="one"; /(.*)(?(?{ $1 eq "one" })(?!))/; print $1'
>
>Normally, $1 would be "one", but I am specifically causing a backtrack
>in that situation, so $1 ends up as "on".
>
>This combines (?(cond)patyes) with (?{...}) and (?!...). The two key
>points are that a negative look-ahead for nothing always fails, and
>the (cond) in a conditional pattern can be a (?{...}) code pattern.
Except that (?{...}) always succeeds (perlre).
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: 16 Sep 2000 10:37:05 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: tutorial for advanced experimental regex features?
Message-Id: <m31yykcpr2.fsf@dhcp11-177.support.tivoli.com>
Jeff Pinyan <jeffp@crusoe.net> writes:
> [posted & mailed]
>
> On Sep 15, Ren Maddox said:
>
> >perl -le '$_="one"; /(.*)(?(?{ $1 eq "one" })(?!))/; print $1'
> >
> >Normally, $1 would be "one", but I am specifically causing a backtrack
> >in that situation, so $1 ends up as "on".
> >
> >This combines (?(cond)patyes) with (?{...}) and (?!...). The two key
> >points are that a negative look-ahead for nothing always fails, and
> >the (cond) in a conditional pattern can be a (?{...}) code pattern.
>
> Except that (?{...}) always succeeds (perlre).
Except when used as the conditional of (?(cond)patyes[|patno])...
(also perlre). I did test the above code, and it does perform as
expected. If you change the internal code to something that is false,
then "one" is printed (instead of "on").
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 15 Sep 2000 22:15:58 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Variables
Message-Id: <m37l8dc9ht.fsf@dhcp11-177.support.tivoli.com>
Bob Walton <bwalton@rochester.rr.com> writes:
> Sam Smith wrote:
> >
> > Whats the difference between a variable declared like ${variable} and
> > $variable ???
>
> There is no difference (other than an extra { and }). But in an
> interpolated string like:
Well, there is a difference... ${"not a valid identifier"} works (with
no strict refs, of course).
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Sat, 16 Sep 2000 10:59:19 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Variables
Message-Id: <Pine.GSO.4.21.0009161051340.12100-100000@crusoe.crusoe.net>
[posted & mailed]
On Sep 15, Ren Maddox said:
>Well, there is a difference... ${"not a valid identifier"} works (with
>no strict refs, of course).
The thing that causes strict refs to cry wolf is not the validity of the
identifier, but the fact that quotes are used. The quotes throw the
symbolic referencing "flag", and strict refs does not like that.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: 16 Sep 2000 10:42:42 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Variables
Message-Id: <m3ya0sbax9.fsf@dhcp11-177.support.tivoli.com>
Jeff Pinyan <jeffp@crusoe.net> writes:
> [posted & mailed]
>
> On Sep 15, Ren Maddox said:
>
> >Well, there is a difference... ${"not a valid identifier"} works (with
> >no strict refs, of course).
>
> The thing that causes strict refs to cry wolf is not the validity of the
> identifier, but the fact that quotes are used. The quotes throw the
> symbolic referencing "flag", and strict refs does not like that.
But that isn't the point. The point is that the ${"blah blah"} syntax
allows things to be used as a variable that are not valid identifiers.
Using either of the non-identifiers I have given in that way works
fine as long as strict refs are off.
perl -le '${"blah blah"}=2; print ${"blah blah"}'
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4342
**************************************