[16923] in Perl-Users-Digest
Perl-Users Digest, Issue: 4335 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 15 14:11:10 2000
Date: Fri, 15 Sep 2000 11:10:24 -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: <969041424-v9-i4335@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Sep 2000 Volume: 9 Number: 4335
Today's topics:
Re: MS-DOS window closes (Tim Hammerquist)
Re: Newbe question <philipg@atl.mediaone.net>
Newbie - Should I learn Perl or Javascript <jimve@ yahoo.com>
Re: Newbie - Should I learn Perl or Javascript <bcaligari@my-deja.com>
Re: obfuscator or compiler <flavell@mail.cern.ch>
Re: obfuscator or compiler nobull@mail.com
Re: obfuscator or compiler <yanick@babyl.sympatico.ca>
Re: obfuscator or compiler <lr@hpl.hp.com>
Re: One program w/ many languages (Arthur T. Murray)
Password protecting a script <g.soper@soundhouse.co.uk>
Re: Password protecting a script <eric.kort@vai.org>
Re: Perl 5.6.0 bug ? GEN33 opened only for output (Lack Mr G M)
Re: Qualifications for new Perl programmer????? (Chris Fedde)
Recursion and prototypes <foo@bar.va>
Re: Recursion and prototypes (John J. Trammell)
Re: Recursion and prototypes <foo@bar.va>
Re: Recursion and prototypes <ren.maddox@tivoli.com>
Re: Regular Expression for matching with email addresse (Rafael Garcia-Suarez)
Re: Regular Expression for matching with email addresse nobull@mail.com
Re: Shortest code for Fibonacci? <christopher_j@uswest.net>
Re: Shortest code for Fibonacci? <russ_jones@rac.ray.com>
Re: Shortest code for Fibonacci? (Abigail)
Re: Shortest code for Fibonacci? <jeffp@crusoe.net>
Re: Shortest code for Fibonacci? (Abigail)
Re: Shortest code for Fibonacci? <ren.maddox@tivoli.com>
Re: Shortest code for Fibonacci? (Abigail)
Re: sprintf() rounding problem <davidhj@mail.com>
Re: sprintf() rounding problem <davidhj@mail.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Sep 2000 17:28:29 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: MS-DOS window closes
Message-Id: <slrn8s4nq7.jp.tim@degree.ath.cx>
mexicanmeatballs@my-deja.com <mexicanmeatballs@my-deja.com> wrote:
> DOS windows have a property that determines whether or not they close
> when the program running in them ends. There's a check box called
> 'Close on exit' under the 'Program' tab in the DOS window properties.
> Uncheck that.
> I may be well off beam here, I don't use perl on windows, so maybe
> you're not running a DOS box at all, but it sounds like it.
When running a .pl script from Win32 Explorer, you don't have the option
of "Close on exit." However, if you create a shortcut and run the
script as a dos command like 'perl script.pl', you have the "Close on
exit".
Of course, I can't remember off the top of my head how to get a dialog
box like that from scratch without scavenging other shortcuts; it's been
too long.
--
-Tim Hammerquist <timmy@cpan.org>
My life has a superb cast but I can't figure out the plot.
-- Ashleigh Brilliant
------------------------------
Date: Fri, 15 Sep 2000 15:25:00 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Newbe question
Message-Id: <gbrw5.5124$g35.512077@typhoon.southeast.rr.com>
Silvo <silvo.vidovic@tel.net.ba> wrote in message
news:8pt5p1$bmip$1@as121.tel.hr...
> How can I extract the Header and Record size of a DBF file opend in Perl
> with
> the open statement ?
> Or, this will do it too, how to get the ASCII value of a character?
perldoc -f ord
hth,
p
------------------------------
Date: Fri, 15 Sep 2000 11:31:38 -0400
From: "Jim Verzino" <jimve@ yahoo.com>
Subject: Newbie - Should I learn Perl or Javascript
Message-Id: <8ptgdi$4bl$1@bob.news.rcn.net>
I am going to spend some time learning some programming for the web. I am
not sure if I should invest in learning perl or javascript first. I have a
business need that would make perl a little smarter from a practicality
perspective but that can be avoided if need be.
I am not new to programming and know some programming languages, but those
are a few years out of date. I do know that learning a new language is
considerable investment though and I want to make the right choice.
Are these competitors or complimentary. What are the pros and cons of one
over the other. Any help would be appreciated.
Jim Verzino
------------------------------
Date: Fri, 15 Sep 2000 16:24:55 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Newbie - Should I learn Perl or Javascript
Message-Id: <8ptifr$427$1@nnrp1.deja.com>
In article <8ptgdi$4bl$1@bob.news.rcn.net>,
"Jim Verzino" <jimve@ yahoo.com> wrote:
> I am going to spend some time learning some programming for the web.
I am
> not sure if I should invest in learning perl or javascript first. I
have a
> business need that would make perl a little smarter from a
practicality
> perspective but that can be avoided if need be.
>
> I am not new to programming and know some programming languages, but
those
> are a few years out of date. I do know that learning a new language
is
> considerable investment though and I want to make the right choice.
>
> Are these competitors or complimentary. What are the pros and cons
of one
> over the other. Any help would be appreciated.
>
> Jim Verzino
>
>
sufficient javascript can be learnt over a weekend
perl is not just for webstuff....it's for everyday life..it's actually
a way of life
it also takes a lifetime to master....but it'll get you doing something
in 5 minutes
brendon - just another clueless newbie
++++
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 15 Sep 2000 17:08:14 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: obfuscator or compiler
Message-Id: <Pine.GHP.4.21.0009151707310.1816-100000@hpplus03.cern.ch>
On 15 Sep 2000, Art Werschulz wrote:
> Does an obfuscator or a compiler exist for perl?
have you looked at the kit of documentation that came with your Perl
installation, or are you expecting us to read it for you?
------------------------------
Date: 15 Sep 2000 17:03:44 +0100
From: nobull@mail.com
Subject: Re: obfuscator or compiler
Message-Id: <u93dj1skv3.fsf@wcl-l.bham.ac.uk>
Art Werschulz <agw@smolyak.cs.columbia.edu> writes:
> Does an obfuscator or a compiler exist for perl?
See FAQ: "How can I hide the source for my Perl program?"
"How can I compile my Perl program into byte code or C?"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 15 Sep 2000 16:34:22 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: obfuscator or compiler
Message-Id: <icsw5.383$3u6.90707@news20.bellglobal.com>
Art Werschulz <agw@smolyak.cs.columbia.edu> wrote:
: Hi.
Hullo
: Does an obfuscator or a compiler exist for perl?
There's a lot of Perl obfuscators lurking around.
...
Oh, you mean the non-wetware type of obfuscator? :)
Well, you can easily write your own, like
#! /usr/bin/perl -p
BEGIN{
$code=q!chomp;($a,$z)=(sort split'',$_)[0,-1];s/./chr(ord($z)-ord($&)+
ord($a))/eg;$_.="\n";!; }$.==1and print qq!$_\nfor(\@_=<DATA>){$code}
eval join'',\@_;\n__DATA__\n\n!and$_=''and next;eval$code;
__END__
Or, even better, unlearn evey good coding pratice you ever learned,
loath whitespaces with passion and try to eradicate them from your
code, turn your back to code-bloating comments, never ever type a
carriage return (your text editor wraps lines, right?), name your
variable after your friends and, when having to choose between
a sound and straight-forward algorithm and a utterly silly one,
always choose the latter. And remember the One True Golden Rule
of Obfuscation: if you don't know what your code do, neither can
they. :)
On the other hand, if you are not ready to become a Perlish
Nyarlathothep, 'perldoc -q compile' offers you some alternatives.
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
Date: Fri, 15 Sep 2000 10:43:40 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: obfuscator or compiler
Message-Id: <MPG.142bffaab9b4720298ad72@nntp.hpl.hp.com>
In article <icsw5.383$3u6.90707@news20.bellglobal.com> on Fri, 15 Sep
2000 16:34:22 GMT, Yanick Champoux <yanick@babyl.sympatico.ca> says...
...
> On the other hand, if you are not ready to become a Perlish
> Nyarlathothep, 'perldoc -q compile' offers you some alternatives.
^^^^^^^^^^^^^
That isn't rot13, so what is it?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 15 Sep 2000 10:02:53 -0800
From: uj797@victoria.tc.ca (Arthur T. Murray)
Subject: Re: One program w/ many languages
Message-Id: <39c2563d@news.victoria.tc.ca>
fred backman, fred@lateral.net, wrote on Fri, 15 Sep 2000:
> A couple of years ago I came across a program listing
> (a hundred lines or so) which could be compiled as many
> different languages, e.g. pascal, perl, c, etc.
> (sorry I cannot remember exactly which ones).
> If I remember correctly, the trick was to use comments
> and trick the individual compilers into thinking it was
> a pascal/perl/c program, when in fact it was all of them.
ATM:
Similar games can be played with words and letters that mean
one thing in English but other things in foreign languages,
and vice versa. Can anybody translate (compile in their heads)
the following snippets of linguistic ambiguity?
it comes (Latin from Vergil)
BEC OCMOTP Y HAC (language? meaning?)
> Does anyone still have this program?
> Has there been similar recent attempts?
>
> Also, does anyone have any other fun-with-languages things, like
ATM:
If under "fun-with-languages things" you would include
upsetting the natural order of evolution;
introducing the ROBO SAPIENS http://robosapiens.mit.edu (q.v.);
releasing an AI Mind in one language to metastasize to others (cf.
http://www.geocities.com/Athens/Agora/7256/mind4th.html Mind.Forth);
bringing about a Cybernetic Economy as prosperity engine for humans;
and racing pell-mell towards the Technological Singularity of Vinge
http://www.ugcs.caltech.edu/~phoenix/vinge/vinge-sing.html --
then look for such fun among the links below.
> the perl poetry contest which appeared in the perl journal?
>
>/Fred
Arthur
--
http://www.geocities.com/mentifex/acm.html : DIY AI
http://www.geocities.com/mentifex/c.html -- AI in C
http://www.geocities.com/mentifex/pascal.html : AI in Pascal
http://www.geocities.com/mentifex/perl.html -- AI in perl
------------------------------
Date: Fri, 15 Sep 2000 17:19:16 +0100
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Password protecting a script
Message-Id: <49fe7f1bceg.soper@soundhouse.co.uk>
I would like a script to be only used once having entered a password. What
would the best way of achieving this be? The script is running on an
Apache server if that helps at all. The script should only ever be used by
a single (the same) person so a single password would be acceptable. In
use the script is called several times in a row, passing itself different
parameters each time but I don't really want the user to have to re-enter
the password within a single session.
Any advice or suggestions will be most appreciated.
Thanks
--
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/
------------------------------
Date: Fri, 15 Sep 2000 12:29:17 -0400
From: "Eric" <eric.kort@vai.org>
Subject: Re: Password protecting a script
Message-Id: <8ptilk$90v$1@msunews.cl.msu.edu>
"Geoff Soper" <g.soper@soundhouse.co.uk> wrote in message
news:49fe7f1bceg.soper@soundhouse.co.uk...
> I would like a script to be only used once having entered a password. What
> would the best way of achieving this be? The script is running on an
> Apache server if that helps at all. <<snip>>
This is a cgi script being served by Apache? Use .htaccess and .htpasswd.
See for example http://faq.clever.net/htaccess.htm
hth
Eric
------------------------------
Date: Fri, 15 Sep 2000 17:05:33 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Perl 5.6.0 bug ? GEN33 opened only for output
Message-Id: <2000Sep15.170533@ukwit01>
In article <m3k8cdzqyx.fsf@dhcp11-177.support.tivoli.com>, Ren Maddox <ren.maddox@tivoli.com> writes:
|>
|> > And here's the output:
|> >
|> > $ input_only.pl
|> > fileno fh0 = 0
|> > fileno fh1 = 1
|> > Filehandle Symbol::GEN1 opened only for output at
|> > /usr/local/lib/perl5/5.6.0/sun4-solaris/IO/Handle.pm line 391.
|> >
|> > $ perl -v
|> >
|> > This is perl, v5.6.0 built for sun4-solaris
|>
|> I do not get that behavior:
|>
|> % input_only.pl
|> fileno fh0 = 0
|> fileno fh1 = 1
|> % perl -v
|>
|> This is perl, v5.6.0 built for i686-linux-thread-multi
Seems to be architecture dependent.
Solaris and Irix6.5 give the error.
Linux does not.
Could it be an issue with the underlying C library?
--
--------- Gordon Lack --------------- gml4410@ggr.co.uk ------------
This message *may* reflect my personal opinion. It is *not* intended
to reflect those of my employer, or anyone else.
------------------------------
Date: Fri, 15 Sep 2000 17:18:38 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <ORsw5.164$W3.171025408@news.frii.net>
In article <8pt8kn$n5t$1@nnrp1.deja.com>,
Brendon Caligari <bcaligari@my-deja.com> wrote:
>In article <Eccw5.17275$a5.244729@news1.rdc1.mb.home.com>,
> andrew-johnson@home.com wrote:
>[ snip snip ]
>
>> practices with Perl, or that sound practices cannot be taught using
>> Perl?
>>
>
>if you start teaching a beginner in perl.....would would he,
>say....know of sorting routines, lists, trees, graphs...
>
Why is it important to learn this stuff as a begining programmer?
Surely we do not teach sentance structure to childeren learning to
talk. Nether do we start first grade math students with Principia
Mathematica.
Make programming interesting and give the student tools to solve a problem
that is real to them. Then if they are interested enough they will start
finding out about all that other neat stuff like linked lists, graphs and
such.
chris
--
This space intentionally left blank
------------------------------
Date: Fri, 15 Sep 2000 17:40:54 +0200
From: Marco Natoni <foo@bar.va>
Subject: Recursion and prototypes
Message-Id: <39C24306.91C31DEB@bar.va>
Hi,
The tiredness make me blind when searching the cause of the warning:
> Prototype mismatch: sub main::search ($$) vs none at
> tree.pl line 30.
running the script:
<code>
1. %TREE=(
2. 1 => 0,
3. 2 => 1,
4. 3 => 2,
5. 4 => 2,
6. 5 => 1,
7. 6 => 1,
8. 7 => 6,
9. 8 => 6
10. );
11.
12. sub search ($$);
13.
14. sub search {
15. my ($level,$parent);
16.
17. $level=shift;
18. $parent=shift;
19.
20. foreach $key (keys %TREE) {
21.
22. if ($TREE{$key}==$parent) {
23. $space=' ' x $level;
24. print "$space -- $key\n";
25. search $level+1,$key;
26. }
27.
28. }
29.
30. }
31.
32. print "BEGIN\n";
33.
34. search 0,0;
</code>
I wonder if somebody can help me. Thank you in advance, and...
Best regards,
Marco
------------------------------
Date: 15 Sep 2000 15:54:36 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Recursion and prototypes
Message-Id: <slrn8s3n9b.f81.trammell@nitz.hep.umn.edu>
On Fri, 15 Sep 2000 17:40:54 +0200, Marco Natoni <foo@bar.va> wrote:
>
> The tiredness make me blind when searching the cause of the warning:
>
> > Prototype mismatch: sub main::search ($$) vs none at
> > tree.pl line 30.
>
<snip>
>12. sub search ($$);
OK.
>14. sub search {
Should read "sub search ($$) {".
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Fri, 15 Sep 2000 18:06:26 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: Recursion and prototypes
Message-Id: <39C24902.A5F5CE51@bar.va>
John,
"John J. Trammell" wrote:
>> The tiredness make me blind when searching the cause of the
>> warning:
>> > Prototype mismatch: sub main::search ($$) vs none at
>> > tree.pl line 30.
>>
>> <snip>
>>12. sub search ($$);
> OK.
>>14. sub search {
> Should read "sub search ($$) {".
Thank you. Meanwhile, I have experimented that, without prototype,
the good old syntax:
&search ($level+1,$key);
works as well as the newest form: Can you see any potential danger in
this syntax?
Best regards,
Marco
------------------------------
Date: 15 Sep 2000 10:51:39 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Recursion and prototypes
Message-Id: <m38zstzm9g.fsf@dhcp11-177.support.tivoli.com>
Marco Natoni <foo@bar.va> writes:
> Hi,
>
> The tiredness make me blind when searching the cause of the warning:
>
> > Prototype mismatch: sub main::search ($$) vs none at
> > tree.pl line 30.
>
> running the script:
>
> <code>
[snip]
> 12. sub search ($$);
> 13.
> 14. sub search {
[snip]
> 30. }
It is complaining that you have not given the same prototype on the
function definition as you did on the declaration. Normally, you can
just combine the two, but for recursion you do (apparently) need the
declaration first. But you also (again, apparently) still need the
prototype on the definition.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 15 Sep 2000 15:18:49 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Regular Expression for matching with email addresses
Message-Id: <slrn8s4fqq.fad.rgarciasuarez@rafael.kazibao.net>
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
Look at the perlfaq9 man page:
"How do I check a valid mail address?"
--
Rafael Garcia-Suarez | http://rgarciasuarez.free.fr/
------------------------------
Date: 15 Sep 2000 17:17:24 +0100
From: nobull@mail.com
To: James Adams <james_adams@yahoo.com>
Subject: Re: Regular Expression for matching with email addresses
Message-Id: <u9vgvxr5nv.fsf@wcl-l.bham.ac.uk>
James Adams <james_adams@yahoo.com> writes:
> I want to verify that strings conform to a typical email address
> format.
Plase read the Perl FAQ _before_ posting to comp.lang.perl.*.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 15 Sep 2000 08:52:36 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <6Brw5.375$eS1.133860@news.uswest.net>
You probably want an explicit formula, like this one:
sub fib
{
my $n = shift;
my $gml = log((1+sqrt(5))/2);
return int( exp($gml*$n)/sqrt(5) + 0.5 );
}
###########
This will give you the nth fibonacci number;
fib(1) = 1
fib(2) = 1
fib(3) = 2
fib(4) = 3
fib(5) = 5
fib(6) = 8
...
fib(10) = 55
------------------------------
Date: Fri, 15 Sep 2000 10:43:25 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39C2439D.8D111C89@rac.ray.com>
Gwyn Judd wrote:
>
> Whoops. Remember kiddies, this is what happens when you make last minute
> changes to mission critical code just before it goes out the door!
The word "poopyhead" is reverberating through the server room.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: 15 Sep 2000 16:15:56 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8s4inq.4mc.abigail@alexandra.foad.org>
Clint Mario Cleetus (cmc77@pantheon.yale.edu) wrote on MMDLXXII September
MCMXCIII in <URL:news:Pine.GSO.4.10.10009142301000.15482-100000@morpheus.cis.yale.edu>:
<> Hi,
<>
<> 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. I wrote a standard subroutine for this:
<>
<> sub Fib
<> {
<> $num = shift;
<>
<> return 1 if $num < 2;
But the zeroth Fibonacci number is 0.
<> $f1 = $f2 = 1;
<> for ($i = 1; $i < $num; $i++)
<> {
<> $f = $f1 + $f2;
<> $f1 = $f2;
<> $f2 = $f;
<> }
<> return $f;
<> }
<>
<> But this seems to be like any other standard C subroutine. Please let me
<> know if you have one-liners or atleast a much more elegant solution for
<> this.
sub Fib {my
($f1, $f2) = (0, 1);
($f1, $f2) = ($f2, $f1 + $f2) for 1 .. shift;
$f1;
}
Of course, once you want to call this function 3 or more times, you'd
use caching. The memoize module might help you with that. (But you'd
need to use recursion then).
Abigail
--
:;$:=~s:
-:;another Perl Hacker
:;chop
$:;$:=~y
:;::d;print+Just.
$:;
------------------------------
Date: Fri, 15 Sep 2000 12:17:09 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <Pine.GSO.4.21.0009151207240.12100-100000@crusoe.crusoe.net>
On Sep 15, Ren Maddox said:
>tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:
>
>> I was shocked! How could Clint Mario Cleetus <cmc77@pantheon.yale.edu>
>> say such a terrible thing:
>> >Hi,
>> >
>> >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. I wrote a standard subroutine for this:
>>
>> perl -le 'print length while ($ / =~ s|(.*)|s ,. *,$ /,ex, $ / . $ &|e)'
>
> Correct: Apparently not...
perl -le 'print+length,while+s/($2)(.*)/$2?"$1$2$2":"."/e'
Ok, so it only prints 1 once. It gets slow as it gets high (obviously).
--
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: 15 Sep 2000 16:33:39 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8s4jp1.4mc.abigail@alexandra.foad.org>
Mark-Jason Dominus (mjd@plover.com) wrote on MMDLXXII September MCMXCIII
in <URL:news:39c1c5ee.5f9e$1f8@news.op.net>:
##
## There may be a faster O(log n) algorithm that is based more directly
## on the identity
##
## F(2n) = F(n)(F(n+1) + F(n-1))
##
## but it's past 2:30 AM here and I can't remember it offhand.
Well, there's a closed formula for Fibonacci numbers, leading to:
sub Fib {
sprintf "%.0f" => ((((1 + sqrt (5)) / 2) ** shift) / sqrt (5));
}
See also:
http://mathworld.wolfram.com/FibonacciNumber.html
Abigail
--
$_ = "\112\165\163\1648\141\156\157\164\150\145\1628\120\145"
. "\162\1548\110\141\143\153\145\162\0128\177" and &japh;
sub japh {print "@_" and return if pop; split /\d/ and &japh}
------------------------------
Date: 15 Sep 2000 10:28:04 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <m3bsxpzncr.fsf@dhcp11-177.support.tivoli.com>
tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:
> >> perl -le 'print length while ($ / =~ s|(.*)|s ,. *,$ /,ex, $ / . $ &|e)'
> >
> > Correct: Apparently not...
>
> The curse of the was working, changed but insufficiently tested code
> strikes again :) How does this grab you?
>
> perl -le 'print length while ($" =~ s|(.*)|s c. *c$ "cex, $ ". $ &|e)
Great.
Took me a long time to catch the fact the $& was not referring to what
I thought it was referring to, but now I still don't see why the
previous one doesn't work.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 15 Sep 2000 17:24:00 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8s4mnf.4mc.abigail@alexandra.foad.org>
Mark-Jason Dominus (mjd@plover.com) wrote on MMDLXXII September MCMXCIII
in <URL:news:39c1c5ee.5f9e$1f8@news.op.net>:
??
?? If you want to compute, say, fib(1000000000), this is definitely the
?? way to go. If I were you I would translate it to C before optimizing
?? it any further.
You also may want to make sure you have enough memory for the process.
fib(1000000000) is a number with over 200 million digits.
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: Fri, 15 Sep 2000 16:08:19 +0100
From: David Hugh-Jones <davidhj@mail.com>
Subject: Re: sprintf() rounding problem
Message-Id: <969030633.490324812@news.uklinux.net>
On Fri, 15 Sep 2000, Abigail wrote:
>It's highly, highly unlikely your users are inputting the numbers as
>floating point numbers and are not willing to switch to character based
>input. In fact, I'm quite certain your users are using characters to
>enter the numbers.
>
hi Abigail.
The user input actually comes in the form of a text config file which gets
read. But, anyway, I don't think the multiply by 100 idea solves it: I
still have to add 17.5% Value Added Tax, which is going to give floating point
results even with integer input.
dave
------------------------------
Date: Fri, 15 Sep 2000 18:15:21 +0100
From: David Hugh-Jones <davidhj@mail.com>
Subject: Re: sprintf() rounding problem
Message-Id: <969038332.1919104262@news.uklinux.net>
On Thu, 14 Sep 2000, mexicanmeatballs@my-deja.com wrote:
>
>Arg, the whole jeopardy thing has confused me....
>
>How's this:
>
>$rounded_up = int($value)==$value? $value : sprintf("%.0f",$value+0.5);
>
>Or have I got the wrong end of the stick?
>You want an always round up right?
>Surely this was too trivial for a newsgroup?
no, I don't always want to round up, I want to round up on 0.5 or more. And it
probably is very trivial, but I am so inept that I haven't yet found a
solution: feel free to offer one!
cheers
dave
------------------------------
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 4335
**************************************