[16961] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4373 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 19 11:05:22 2000

Date: Tue, 19 Sep 2000 08: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)
Message-Id: <969375906-v9-i4373@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 19 Sep 2000     Volume: 9 Number: 4373

Today's topics:
    Re: (OpenVMS) EOF with autoflushed file <dan@tuatha.sidhe.org>
    Re: 2 Questions <n0spam@mail.com>
    Re: 2 Questions <d.frey@aixigo.de>
    Re: 2 Questions (Randal L. Schwartz)
    Re: Embed the perl mister <amonotod@netscape.net>
    Re: Embed the perl mister <yanick@babyl.sympatico.ca>
    Re: Embed the perl mister geoff@jungle.com
    Re: Is there a DBI that will connect to MS SQL Server? zirconx@my-deja.com
    Re: Join our team (Gwyn Judd)
    Re: Matching anything but a certain string <the_big_pig@my-deja.com>
        Passing references or typeglobs to xsub? <eric.kort@vai.org>
    Re: Pure perl encrypt/decryption? <andrew.flisher@onyx.net>
    Re: Range operator with "... /^$/" ollie_spencer@my-deja.com
    Re: Range operator with "... /^$/" <ren.maddox@tivoli.com>
    Re: Regular Expressions: Counting matches? <dfan@harmonixmusic.com>
    Re: Regular Expressions: Counting matches? <sariq@texas.net>
    Re: script critique requested (Gwyn Judd)
        Send e-mail in HTML format with sendmail <d@i.am>
    Re: Shortest code for Fibonacci? <jcook@strobedata.com>
    Re: Shortest code for Fibonacci? (Gwyn Judd)
        Split NS Log File fperkins@my-deja.com
    Re: sprintf() rounding problem <davidhj@mail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 19 Sep 2000 13:48:07 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: (OpenVMS) EOF with autoflushed file
Message-Id: <r8Kx5.221$pP.29680@news1.rdc1.ct.home.com>

BibiLoloDeSaintMalo <coucoureux.p@fr.ibm.com> wrote:
> Hello,

> When I do a 'print' in a file in autoflush mode I receive an error : end
> of file detected.
> Why?

That's very odd. Could be any number of reasons, including a spurious
error. What version of perl, and what version & architecture of VMS?

> And how can do to write in my file

Just write. It should work if there really isn't anything wrong.

				dan


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

Date: Tue, 19 Sep 2000 09:48:02 -0400
From: SM <n0spam@mail.com>
Subject: Re: 2 Questions
Message-Id: <39C76E92.890D41B@mail.com>

jfp wrote:
> 
> Looking at this thread as a whole nobody recommends Perl as a first language
> then?........
> 
> Has anyone here learnt Perl first?
> 
> jfp

I would suggest that anyone who would like to read others thoughts on
Perl as a first language take a look at the thread "Qualifications for
new Perl Programmer???"

Sara


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

Date: Tue, 19 Sep 2000 16:28:57 +0200
From: Daniel Frey <d.frey@aixigo.de>
Subject: Re: 2 Questions
Message-Id: <39C77829.33B74BEB@aixigo.de>

Hi,

SM wrote:
> I would suggest that anyone who would like to read others thoughts on
> Perl as a first language take a look at the thread "Qualifications for
> new Perl Programmer???"

I think Perl is a write-only-language - you can't read Perl ;)

(SCNR)

> Sara

Regards, Daniel

--
Daniel Frey

aixigo AG - Financial Research and Education
Hammerweg 4, 52074 Aachen, Germany
Tel: +49 (0)241 96106-17, Fax: +49 (0)241 96106-20
EMail: D.Frey@aixigo.de


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

Date: 19 Sep 2000 07:32:30 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: 2 Questions
Message-Id: <m1k8c8xxj5.fsf@halfdome.holdit.com>

>>>>> "Andreas" == Andreas Kähäri <andkaha@hello.to.REMOVE> writes:

Andreas> IMHO, a language like Perl (non-standard, huge, extensible, tons of
Andreas> libraries) might be a little bit too much for a complete newbie to
Andreas> comprehend (that goes for Java and C++ too). My first real language
Andreas> was Pascal. Its complete grammar may be written on at most 2 sheets of
Andreas> A4 paper. Yes, you're confined in a very tight space where you're not
Andreas> allowed to do very much, but you can learn a lot about programming
Andreas> from it.

And Smalltalk's entire syntax can be written on the back of a business
card (literally), *and* you can do serious work with it.  I suggest
Smalltalk as a good first language, with free non-commercial versions
available from all the big vendors, and a free open-source version
available at <www.squeak.org>.  From Smalltalk we got *true* OO, GUIs,
IDEs, and everything else that people rave about, but Smalltalk had it
in 1980!

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Tue, 19 Sep 2000 13:23:43 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Embed the perl mister
Message-Id: <8q7pc6$ejv$1@nnrp1.deja.com>

In article <39C7482C.2EED3618@hughesmedia.co.uk>,
  Tom Fotheringham <tom@hughesmedia.co.uk> wrote:
> I really want to use Perl in a similar way as PHP.  How can I embed
perl
> programs into HTML.  One way I thought of doing it was to read in top
> and bottom HTML pages from within perl and the output them.
>
> Can anyone shed some light on a more convientient way of doing it?
> Any pointers would be gratefully recieved.
>
> Tom
> :wq
>
>
SSI FAQ-
http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html

amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 19 Sep 2000 14:25:30 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Embed the perl mister
Message-Id: <uHKx5.273121$1h3.5759821@news20.bellglobal.com>

Tom Fotheringham <tom@hughesmedia.co.uk> wrote:
: I really want to use Perl in a similar way as PHP.  How can I embed perl
: programs into HTML.  One way I thought of doing it was to read in top
: and bottom HTML pages from within perl and the output them.

: Can anyone shed some light on a more convientient way of doing it?
: Any pointers would be gratefully recieved.

I personally love the Apache module HTML::Embperl that, surprise,
is used to embed Perl code in HTML documents. It's available at 
any good CPAN mirror site near you. 

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: Tue, 19 Sep 2000 15:34:15 +0000
From: geoff@jungle.com
To: Tom Fotheringham <tom@hughesmedia.co.uk>
Subject: Re: Embed the perl mister
Message-Id: <39C78777.D0305608@jungle.com>

Tom Fotheringham wrote:
> 
> I really want to use Perl in a similar way as PHP.  How can I embed perl
> programs into HTML.  One way I thought of doing it was to read in top
> and bottom HTML pages from within perl and the output them.
> 
> Can anyone shed some light on a more convientient way of doing it?
> Any pointers would be gratefully recieved.
> 
> Tom
> :wq

Checkout thess links for some popular solutions:

http://perl.apache.org/#embed
http://www.template-toolkit.org

BTW
:x!


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

Date: Tue, 19 Sep 2000 13:10:44 GMT
From: zirconx@my-deja.com
Subject: Re: Is there a DBI that will connect to MS SQL Server?
Message-Id: <8q7ok2$dpq$1@nnrp1.deja.com>

In article <7Nxx5.5161$Vu5.278728@newsread2.prod.itd.earthlink.net>,
  "Captain Ahab" <cublai@earthlink.net> wrote:
>
> > but can I connect
> > to a modern SQLServer (is that like 7.0 or 2000?) via DBD/DBI
> > Perl on linux? Which one?
> >
> > Can I just reach it with DBD:ODBC? Thanks for any help.
>
> I have had no problems connecting to MSSQL 7.0/2000 with DBI/DBD::ODBC
on
> NT.

Thank you.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 19 Sep 2000 13:18:46 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Join our team
Message-Id: <slrn8septk.o36.tjla@thislove.dyndns.org>

I was shocked! How could Joe Spammy <joegetty@mediaspam.net>
say such a terrible thing:
>Looking spam an spam that spam familiar spam unix spam has spam good
>understanding spam HTML. spam Knowledge spam regular spam is preferred.
>You spam be spam charge spam creating spam testing spam files that
>are spam with spam proprietary software. spam  spam may spam done
>offsite spam your spam hours. spam Compensation spam consists spam wages and
>equity spam a spam internet startup.
>
>Please e-mail me your resume in either MS Word, HTML, or ASCII format.

I didn't know ASCII had a format. Alternatively, most HTML and word
documents are written in ASCII are they not? Ergo this is redundant, I
could send in my resume in XML and it would be fine do you think?

-- 
Gwyn "I am not a spammer" Judd
(print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The limits of my language means the limits of my world.
		-- Ludwig Wittgenstein


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

Date: Tue, 19 Sep 2000 14:21:28 GMT
From: THE BIG PIG <the_big_pig@my-deja.com>
Subject: Re: Matching anything but a certain string
Message-Id: <8q7sog$j01$1@nnrp1.deja.com>

In article <39BB314E.ED677201@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> Oink!
>
> Godzilla!
> --
> Androids And More.
>   http://la.znet.com/~callgirl/android.html
>
> TEST SCRIPT:
> ____________
>
> #!/usr/local/bin/perl
>
> print "Content-type: text/plain\n\n";
>
> $string = "Kira is not really a big fat pig with a Duroc hog's arse.
>          Souuuie pig pig pig pig pig!
>            Souuuie pig pig pig pig!
>              Souuuie pig pig pig!
>                Souuuie pig pig!
>                 Souuuie pig!
>                  Souuuuie!
>                    pig!";
>
> print "Input:\n\n$string\n\n";
>
> $string =~ s¡pig¡ô¿ô¡gi;
>
> print "Processing:\n\n$string\n\n";
>
> $string =~ s¡not ¡¡;
>
> $string =~ s¡ô¿ô¡pig¡g;
>
> print "Output:\n\n$string";
>
> exit;
>
> PRINTED RESULTS:
> ________________
>
> Input:
>
> Kira is not really a big fat pig with a Duroc hog's arse.
>          Souuuie pig pig pig pig pig!
>            Souuuie pig pig pig pig!
>              Souuuie pig pig pig!
>                Souuuie pig pig!
>                 Souuuie pig!
>                  Souuuuie!
>                    pig!
>
> Processing:
>
> Kira is not really a big fat ô¿ô with a Duroc hog's arse.
>          Souuuie ô¿ô ô¿ô ô¿ô ô¿ô ô¿ô!
>            Souuuie ô¿ô ô¿ô ô¿ô ô¿ô!
>              Souuuie ô¿ô ô¿ô ô¿ô!
>                Souuuie ô¿ô ô¿ô!
>                 Souuuie ô¿ô!
>                  Souuuuie!
>                    ô¿ô!
>
> Output:
>
> Kira is really a big fat pig with a Duroc hog's arse.
>          Souuuie pig pig pig pig pig!
>            Souuuie pig pig pig pig!
>              Souuuie pig pig pig!
>                Souuuie pig pig!
>                 Souuuie pig!
>                  Souuuuie!
>                    pig!
>
Fantastic!
--
(:)OIBK!
THE BIG PIG
(:)PIGS (Poor Innocent Guys Society)
http://hometown.aol.com/kcds3/webprof/index.htm


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 19 Sep 2000 09:39:01 -0400
From: "Eric" <eric.kort@vai.org>
Subject: Passing references or typeglobs to xsub?
Message-Id: <8q7q65$19uo$1@msunews.cl.msu.edu>

Can I pass a perl reference or typeglob to a XSUB module written in C?  If
so, how?

tia,
Eric




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

Date: Tue, 19 Sep 2000 14:30:57 +0100
From: Andy Flisher <andrew.flisher@onyx.net>
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <MPG.14317ae9c5de7dc3989687@nntp.onyx.net>

In article <8q7fmf$3pm$1@nnrp1.deja.com>, grymoire@my-deja.com says...
> In article <8q60qe$eni$1@nnrp1.deja.com>,
>   grymoire@my-deja.com wrote:
> 
> > That should do it! Thanks!
> Oops! it only encrypts the first 8 characters.
> I'll have to do it in chunks, I guess

Encrypting's not too much of a hardship, just through 8 Bytes at a time 
at it, it's the decoding that gave me grief.

Splitting text on the way in is easier as it's 8 chars, but there's no 
guarantee that you're gonna get 8 chars back.  Ideally I would like to 
append the encrypted chunks together into one string and output to 
wherever, and then read back int, split, and decrypt, but can't fathom 
out how?

The only thought that sprang to mind was to either seperate the chunks 
with \n and then chomp on the way back in, but to be honest haven't tried 
it.  Theories would be useful on this one, else I'm back to piping output 
through PGP again :-( 

-- 
Andy Flisher

'All postings are a reflection of my state of mind,
and not necessarily of any worthwhile opinion'

news@flish.co.uk    http://www.flish.co.uk


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

Date: Tue, 19 Sep 2000 13:38:21 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Range operator with "... /^$/"
Message-Id: <8q7q8a$fnq$1@nnrp1.deja.com>

In article <Sjxx5.1466$z9.130484@news20.bellglobal.com>,
  yanick1@sympatico.ca wrote:
> ollie_spencer@my-deja.com wrote:
> : I agree. I'm covered by embarassment,
>
> 	Could be worse. Could be monkey livers. :)
>
> : since my code DOES have "if", but
> : in my hurry to post, I used the incorrect "while". And in my "REAL"
> : code, I do chomp.
>
> 	So can we see a minimal subset of your real code that
> 	reproduce the problem you are encountering. Pretty please
> 	with sugar on top? :)
>

 Well, since you really seem to want to see it in all it's glory ;-)
Actually I have resolved the problem to some degree(with you and
others' help) - and have posted pseudocode of the "corrected and
working" code in an earlier post.

As in many cases, the problem arose from multiple sources.

The original test file is dumped from a Unix box and ftp'd to an NTFS
fileserver where I pick it up. The ftp operation converts the UNIX \x0a
line separator to \x0d\x0a, which begins my problem.

The default $/ in my "active"perl implementation is \x0a. chomp()
always removes what is contained in $/ from the end of the line; in my
case this leaves the \x0d intact. I saw this earlier in the my emacs
editor, but didn't realize its significance, so nulled it away(again
with internet help).

Today I will experiment to see if setting $/ to the WIN line terminator
will cause my original code ( with the  ... /^$/ ) to work. Meanwhile,
I have found joy by using ... /^\x0d^/ as the 2nd expression in the
range argument, thus accounting for the residual \x0d in the file.
Another poster suggested I might solve the problem by using 2 chop()s
instead of a single chomp. I will experiment with this also.

Thank again for your help. perl wins again - SUperlATIVE!!!

ollie spencer


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 18 Sep 2000 23:53:52 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Range operator with "... /^$/"
Message-Id: <m3lmwpasnz.fsf@dhcp11-177.support.tivoli.com>

ollie_spencer@my-deja.com writes:

> Yep, I run binmode() after opening and before using the file.
> I'm thinking now that I may have to convert all the "0d0a" newlines to
> just "0a" (with perl, of course) before I will be able to do what I
> want. I thought that $/ became "0d0a" automatically when it encountered
> a windows file, but right now that seems to not be true. I'm trying to
> force it-

Don't call binmode() -- that is causing the problem.  You are treating
the file as a binary file, but trying to access it as a text file.
Pick one, and stick with it.  In this case, turning on binmode() turns
*off* the magic handling of "0d0a".

When Brendon and I each asked if you were calling binmode(), the
intent was to indicate that it sounded like you were when you
shouldn't.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 19 Sep 2000 09:28:00 -0400
From: Dan Schmidt <dfan@harmonixmusic.com>
Subject: Re: Regular Expressions: Counting matches?
Message-Id: <wksnqw7bq7.fsf@turangalila.harmonixmusic.com>

Larry Rosler <lr@hpl.hp.com> writes:

| In article <wk66nt9vzk.fsf@turangalila.harmonixmusic.com> on 18 Sep 2000 
| 18:27:27 -0400, Dan Schmidt <dfan@harmonixmusic.com> says...
| > Chovy <johndoyle33@hotmail.com> writes:
| 
| > | how do I find out how many times it's been matched?
| > 
| > $num_matches = () = m/<a href=/ig;
| 
| Yuk.  That is the second time that gross and inefficient solution has 
| been posted in this thread.
| 
| perlfaq4: How can I count the number of occurrences of a substring 
| within a string?"

My apologies, and thanks for the correction.  When I benchmarked, the
solution in the FAQ (simply iterating through the successive (scalar
context) results of //g and incrementing a variable) is indeed twice
as fast as my suggestion.

Gross is in the eyes of the beholder, on the other hand.  I find it
grosser to go through a loop incrementing a variable than to determine
it in a single statement.  My functional tendencies showing, I guess.

-- 
                 Dan Schmidt | http://www.dfan.org
Honest Bob CD now available! | http://www.dfan.org/honestbob/cd.html


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

Date: Tue, 19 Sep 2000 09:37:59 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Regular Expressions: Counting matches?
Message-Id: <39C77A47.FBB2ED1A@texas.net>

Dan Schmidt wrote:
> 
> Larry Rosler <lr@hpl.hp.com> writes:
> 
> | In article <wk66nt9vzk.fsf@turangalila.harmonixmusic.com> on 18 Sep 2000
> | 18:27:27 -0400, Dan Schmidt <dfan@harmonixmusic.com> says...
> | > Chovy <johndoyle33@hotmail.com> writes:
> |
> | > | how do I find out how many times it's been matched?
> | >
> | > $num_matches = () = m/<a href=/ig;
> |
> | Yuk.  That is the second time that gross and inefficient solution has
> | been posted in this thread.
> |
> | perlfaq4: How can I count the number of occurrences of a substring
> | within a string?"
> 
> My apologies, and thanks for the correction.  When I benchmarked, the
> solution in the FAQ (simply iterating through the successive (scalar
> context) results of //g and incrementing a variable) is indeed twice
> as fast as my suggestion.
> 
> Gross is in the eyes of the beholder, on the other hand.  I find it
> grosser to go through a loop incrementing a variable than to determine
> it in a single statement.  My functional tendencies showing, I guess.

What makes you think that *your* solution doesn't "go through a loop"?

If, for some odd reason, you object to the bracketed block, just use:

$count++ while $string =~ /-\d+/g;

- Tom


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

Date: Tue, 19 Sep 2000 14:45:17 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: script critique requested
Message-Id: <slrn8seuvp.o36.tjla@thislove.dyndns.org>

I was shocked! How could Steve Allan <stevea@wrq.com>
say such a terrible thing:
>
>For those who have the time and interest, I could really benefit from
>some constructive criticism.  I've been teaching myself Perl for the
>last 8 months and have learned a lot from lurking around on this
>forum.  But there's no substitute for writing code and having people
>disect it.

It's a very nice piece of code actually. Looks like you've put a lot of
work into it.

>my(
>   $dir1, $dir2,		# directories to compare
>   @dir1files, @dir2files,	# lists of files
>   $start_dir,			# where we started
>   %count,			# hash counting each file
>   @dir1_only, @dir2_only,	# holds files unique to dir
>   @dir1_dir2,			# files common to both dirs
>   @files_same, @files_diff,	# results of file compare
>);

My personal preference is to declare variable names close to where they
are used rather than all at the top. This makes it easier to know what
they are used for.

>#--------------------------------------------------
>#
># Compute set differences and intersection
>#     * walk list one and assign 1 to hash
>#     * walk list two and add 2 to hash
>#         - values of 1 list 1 only
>#         - values of 2 list 2 only
>#         - values of 3 intersection
>#
>#--------------------------------------------------
>for (@dir1files) { $count{$_}  = 1 }
>for (@dir2files) { $count{$_} += 2 }
>while(my($k, $v) = each %count) {
>   if($v == 1)    { push @dir1_only, $k }
>   elsif($v == 2) { push @dir2_only, $k }
>   elsif($v == 3) { push @dir1_dir2, $k }
>   else { warn "program error - invalid value $v for $k" }
>}

I think you could do this easier using three hashes. Assuming you have
the filenames in %dir1files and %dir2files then:

%dir1only = %dir1files;
delete @dir1only{keys %dir2files};
# %dir1only contains only the files in directory 1

%dir2only = %dir2files;
delete @dir2only{keys %dir1files};
# ditto but vice versa

%dir1_dir2 = (%dir1files, %dir2files); # union
delete @dir1_dir2{keys %dir1only, keys %dir2only};
# contains only those appearing in both

This may even be more efficient although your method is pretty good too.

>print ONLYONE $stdout ? "=== $dir1 only ===\n" : '', 
>  join "\n", sort @dir1_only, "\n" if @dir1_only;
>print ONLYTWO $stdout ? "=== $dir2 only ===\n" : '', 
>  join "\n", sort @dir2_only, "\n" if @dir2_only;

{
    local ($, , $\) = ("\n" , "\n");

    print ONLYONE $stdout ? "=== $dir1 only ===" : '';
    print ONLYONE sort keys %dir1only if %dir1only;

    # etc...
}

One of the rare times where it is correct to use "local".

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
You can learn many things from children.  How much patience you have,
for instance.
		-- Franklin P. Jones


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

Date: Tue, 19 Sep 2000 21:02:46 +0700
From: "Dimitri" <d@i.am>
Subject: Send e-mail in HTML format with sendmail
Message-Id: <8q7s16$3fi$1@news.asiaaccess.net.th>

How to send e-mail in HTML format with sendmail?  The html source appear in
the e-mail I send.

open (MAIL, "|$emailprogram");
print MAIL ("To: $youremailadr \n");
print MAIL ("From: $ouremailadr \n");
print MAIL <<eof ;
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
My html here...
</BODY>
</HTML>
eof
close MAIL;





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

Date: Tue, 19 Sep 2000 07:12:22 -0700
From: Jim Cook <jcook@strobedata.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39C77446.F856E5C2@strobedata.com>

> ^^ () How do you raise powers in constant time?

According to the Intel Pentium Family User's Manual, Volume 3:
Architecture and Programming Manual:

Page 25-85 says that F2XM1 (Compute 2**X-1) takes between 13 and 57
clocks. Under "Notes" it says that "Values other than 2 can be
exponentiated using the formula x**y=2(y*log2(x))

y*log2(x) is 22 to 111 clocks. Multiply is 1 to 7 clocks.

All are O(1)

So here's my real question to Abigail. From your postings, I have
gathered that you are a very intelligent and learned coder of perl. It
seems that you were implying that raising powers took longer and longer
for larger and larger inputs to the function. I can't believe that you
would think perl would to an iterative multiply for powers, so I feel
that I must be missing something. Would you please clarify your question
so I am less confused?

Thanks.

--
jcook@strobedata.com  Live Honourably    4/1 - 4/3 + 4/5 - 4/7 + . . .
2000 Tuesdays: Feb/last 4/4 6/6 8/8/ 10/10 12/12 9/5 5/9 7/11 11/7 3/14
Strobe Data Inc. home page   http://www.strobedata.com
My home page    O-           http://jcook.net


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

Date: Tue, 19 Sep 2000 15:00:39 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8sevsk.o36.tjla@thislove.dyndns.org>

I was shocked! How could Jim Cook <jcook@strobedata.com>
say such a terrible thing:
>> ^^ () How do you raise powers in constant time?
>
>According to the Intel Pentium Family User's Manual, Volume 3:
>Architecture and Programming Manual:

>y*log2(x) is 22 to 111 clocks. Multiply is 1 to 7 clocks.
>
>All are O(1)

>that I must be missing something. Would you please clarify your question
>so I am less confused?

For a certain subset of the real numbers it is possible to raise powers
in bounded time*. On the other hand, in general it is not possible to
raise powers of arbitrary real numbers in constant time. Does that help
your confusion?

* not necessarily the same as constant time

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)

      "The foolish reject what they see and not what they think;
      the wise reject what they think and not what they see."

 Huang Po


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

Date: Tue, 19 Sep 2000 14:54:34 GMT
From: fperkins@my-deja.com
Subject: Split NS Log File
Message-Id: <8q7umv$la5$1@nnrp1.deja.com>

I have a log file that I need to split in order to analyze the fields.

It doesn't seem to be tab delimted so I cant do: split /\t/;

If I do split /\s/; it's extremely messy as you can see below from a
sample line:

207.179.196.120 - - [31/Jul/2000:22:05:02 -0000] "GET / HTTP/1.0" 200
737 "http://www.someurl.com/url.html" "Mozilla/4.06 [en] (Win98;
I)" "INTERSE=20724114964484603"

If anyone has experience in splitting NS log files, I would appreciate
some info on the best way of doing this.

TIA,

Frank


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 19 Sep 2000 15:46:52 +0100
From: David Hugh-Jones <davidhj@mail.com>
Subject: Re: sprintf() rounding problem
Message-Id: <969375053.788717053@news.uklinux.net>


Thanks to all who answered this: for future reference for anyone with my
problem:

if you need to round the result of a floating point calculation, with 0.5
always being rounded up - e.g. tax calculations etc.
 - round your result to 4 sig figs, to avoid evil 0.49999999s
 - multiply by 100 to put things into cents/pennies
 - if ($result - int($result) >= 0.5) { $result = int($result+1)} else {$result
= int($result)}
 - divide by 100 again

wfm

dave


On Fri, 15 Sep 2000, Chris Fedde wrote:
>In article <969030633.490324812@news.uklinux.net>,
>David Hugh-Jones  <davidhj@mail.com> wrote:
>>
>>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
>
>It's possible to do fixed place math in Perl.  One way is to use
>Math::BigInt.  Multiply incoming values by the right adjuster, Do
>what you want, then stuff a decimal in on output.  For rounding
>money you need to pick a method that preserves pennies. One method
>that is common is round up if thousandths is 5 or greater and down
>otherwise.  Since half of the transactions are credits and half
>are debits the pennies will balance out.
>
>    #!/usr/bin/perl
>
>    use warnings;
>    use strict;
>    use Math::BigInt;
>    use constant Places=>3;
>
>    my $balance = Math::BigInt->new( '123456784'.'0'x Places );
>    my $rate = Math::BigInt->new( 17.5 * 10**Places );
>
>    my $newbal = $balance + $balance*$rate/12;
>    my $dist   = $newbal/45;
>    my $other  = $newbal/7;
>
>    print join(" ", $newbal, $dist, $other), "\n";
>    print join(" ", map {displaycents($_)} $newbal, $dist, $other), "\n";
>
>    sub displaycents
>    {
>	my $amt = shift;
>
>	$amt += substr($amt, -1, 1) < 5 ? 0 : 10;
>
>	$amt = $amt->bnorm;
>	substr($amt, -1*Places, 0) = ".";
>	substr($amt, -1, 1) = '';
>	return $amt;
>    } 
>
>chris
>-- 
>    This space intentionally left blank


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

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 4373
**************************************


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