[14020] in Perl-Users-Digest
Perl-Users Digest, Issue: 1430 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 19 14:16:03 1999
Date: Fri, 19 Nov 1999 11:15:45 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <943038945-v9-i1430@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 19 Nov 1999 Volume: 9 Number: 1430
Today's topics:
Re: Even Numbers (Abigail)
Re: Even Numbers (Simon Cozens)
Re: Even Numbers (Abigail)
Re: Executeable into a Variable <slanning@bu.edu>
Re: Fetch Dilbert. (Abigail)
Re: Fetch Dilbert. (Abigail)
Re: Fetch Dilbert. (Abigail)
Re: Fetch Dilbert. <gellyfish@gellyfish.com>
Re: Fetch Dilbert. <uri@sysarch.com>
Re: file descriptors already used when perl starts lee.lindley@bigfoot.com
Re: file descriptors already used when perl starts <lr@hpl.hp.com>
Re: file descriptors already used when perl starts g0177325@my-deja.com
Re: file descriptors already used when perl starts (M.J.T. Guy)
Re: file descriptors already used when perl starts (M.J.T. Guy)
Re: File::Find on Win32 :-( - getit4.pl (0/1) (Scott McMahan)
Re: foreach on a hash within a hash (Thunderdust (TomH))
Fork Children w/ Expect <jim.mosier@usa.net>
Re: Generating pi <jarrowwx@NOSPAM.home.com>
Re: Generating pi (Ilya Zakharevich)
Help me read my database please <slimy@bigfoot.com>
Re: Help me read my database please <sp00fD@yahoo.com>
Help Uploading Files to Web Site <richard@avocation.demon.co.uk>
Re: Help Uploading Files to Web Site <gellyfish@gellyfish.com>
Help: 501 Protocol error <p146046183@ntu.edu.sg>
Re: How do I get a list of users in an NT domain? <tim.westlakeNOtiSPAM@myremarq.com.invalid>
Re: How to make the comparable also hashable? <johnlin@chttl.com.tw>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Nov 1999 12:18:48 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Even Numbers
Message-Id: <slrn83b5aj.l1a.abigail@alexandra.delanet.com>
Simon Ramsden (sramsden@orbit-internet.net) wrote on MMCCLXX September
MCMXCIII in <URL:news:3833d31f.0@news.proweb.co.uk>:
|| Hello,
|| I'm a newbie trying to write a script that recognises even numbers. I'm
|| having to make if/ elsif statements for every number in the range that I
|| expect. I know this is the wrong way to do it, so can someone tell me how to
|| interpret an even number?
Use the easy to remember, symmetric functions:
sub is_even;
sub is_odd;
sub is_even {!$_ [0] || is_odd abs $_ [0] - 1}
sub is_odd { $_ [0] && is_even abs $_ [0] - 1}
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 19 Nov 1999 18:23:46 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: Even Numbers
Message-Id: <slrn83b5di.qud.simon@othersideofthe.earth.li>
Abigail (comp.lang.perl.misc):
>Use the easy to remember, symmetric functions:
This is an IAQ, isn't it? Did you read the Perl IAQ?
> sub is_even {!$_ [0] || is_odd abs $_ [0] - 1}
> sub is_odd { $_ [0] && is_even abs $_ [0] - 1}
Oh, I prefer a simpler approach.
sub is_even {!is_odd($_[0])}
sub is_odd {!is_even($_[0])}
--
Honk if you hate bumper stickers that say "Honk if ..."
------------------------------
Date: 19 Nov 1999 12:49:13 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Even Numbers
Message-Id: <slrn83b73f.l1a.abigail@alexandra.delanet.com>
Simon Cozens (simon@brecon.co.uk) wrote on MMCCLXXI September MCMXCIII in
<URL:news:slrn83b5di.qud.simon@othersideofthe.earth.li>:
?? Abigail (comp.lang.perl.misc):
?? >Use the easy to remember, symmetric functions:
??
?? This is an IAQ, isn't it? Did you read the Perl IAQ?
Where do you think the IAQ got that answer from?
?? > sub is_even {!$_ [0] || is_odd abs $_ [0] - 1}
?? > sub is_odd { $_ [0] && is_even abs $_ [0] - 1}
??
?? Oh, I prefer a simpler approach.
??
?? sub is_even {!is_odd($_[0])}
?? sub is_odd {!is_even($_[0])}
Ah, but my solution is correct, and yours isn't.
Abigail
--
tie $" => A; $, = " "; $\ = "\n"; @a = ("") x 2; print map {"@a"} 1 .. 4;
sub A::TIESCALAR {bless \my $A => A} # Yet Another silly JAPH by Abigail
sub A::FETCH {@q = qw /Just Another Perl Hacker/ unless @q; shift @q}
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 19 Nov 1999 13:06:08 -0500
From: Scott Lanning <slanning@bu.edu>
Subject: Re: Executeable into a Variable
Message-Id: <kusogcquzjj.fsf@strange.bu.edu>
kevinh@inetplus.net (Kevin) writes:
>How can I execute a program or another script and put
>its output into a Variable?
'perldoc perlop', search for '`STRING`'.
(note backticks, not apostrophe)
--
"One should not confuse this craving for change and novelty with the
indifference of play which is in its greatest levity at the same time
the most sublime and indeed the only true seriousness." --Georg Hegel
------------------------------
Date: 19 Nov 1999 11:42:47 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Fetch Dilbert.
Message-Id: <slrn83b372.l1a.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCCLXIX September MCMXCIII
in <URL:news:38356c2f.3385851@news.skynet.be>:
@@ perldoc@my-deja.com wrote:
@@
@@ >> open DISPLAY, "| $viewer" or die "Failed to open viewer.\n";
@@ >> print DISPLAY $image;
@@ >> close DISPLAY or die "Failed to close viewer.\n";
@@ >
@@ >OK, I'll take the troll.
@@
@@ Otherwise, I will.
@@
@@ What, no "binmode"?
Of course not. Are you suggesting I should use untested code, with
"binmode" being a no-op on my platform?
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 19 Nov 1999 11:48:49 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Fetch Dilbert.
Message-Id: <slrn83b3ic.l1a.abigail@alexandra.delanet.com>
that's my address' Newton (nospam.newton@gmx.li) wrote on MMCCLXX
September MCMXCIII in <URL:news:38346210.436580276@news.nikoma.de>:
..
.. Well, yes -- but putting Perl into /opt (by default, or for other
.. reasons) reminded me of HP-UX. Linux puts it into /usr/local by
.. default, IIRC.
Linux doesn't put anything anywhere by default. Each distribution has
its own little twisted idea of a file layout - the horrors of never
knowing where something on a Unix is all over again, but this time,
all on the same "platform".
Perl isn't part of the system, IMO, hence, it's either /usr/local, or
/opt. I prefer using /opt for somewhat larger packages; it makes it
easier to have multiple versions living next to each other. (I have a
/opt/perl and a /opt/devperl. ;-)
The fact it's Linux is not really relevant. It's my box; that's the
reason it's in /opt.
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)))))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 19 Nov 1999 11:55:44 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Fetch Dilbert.
Message-Id: <slrn83b3vb.l1a.abigail@alexandra.delanet.com>
Uri Guttman (uri@sysarch.com) wrote on MMCCLXX September MCMXCIII in
<URL:news:x766yzsbvw.fsf@home.sysarch.com>:
!!
!! i never liked having /opt. i have it only for solaris specific patches
!! and packages. i never put anything else in there. same with /usr. other
!! than under local i never touch it so it is only sun stuff (except for
!! some minor symlinks and X stuff).
The reason I prefer /opt over /usr/local is this:
$ rm -rf /opt/perl # Poof. All of this package gone.
With /usr/local, you have to browse through /usr/local/bin and figure
out which binaries/scripts come with Perl and which don't. Not to mention
figuring out which man pages need to disappear.
And as an added benefit, for a development version of perl, I can
just do:
$ ./Configure -Dprefix=/opt/devperl
and make/make test/make install the stuff without it overwriting any
of the files belong to the stable version of perl.
Abigail
--
tie $" => A; $, = " "; $\ = "\n"; @a = ("") x 2; print map {"@a"} 1 .. 4;
sub A::TIESCALAR {bless \my $A => A} # Yet Another silly JAPH by Abigail
sub A::FETCH {@q = qw /Just Another Perl Hacker/ unless @q; shift @q}
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 19 Nov 1999 09:08:28 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Fetch Dilbert.
Message-Id: <3835138c_1@newsread3.dircon.co.uk>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "P'tmaN" == Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> writes:
>
> P'tmaN> Well, yes -- but putting Perl into /opt (by default, or for other
> P'tmaN> reasons) reminded me of HP-UX. Linux puts it into /usr/local by
> P'tmaN> default, IIRC.
>
> i
> think they should only put the core unix programs and libs in /usr and
> the third party (how do you define 3rd party in that world? :-) programs
> should go into /usr/local.
>
But isnt Perl core now ?
/j\
--
"Michael Ancram, you haven't got a hope in hell of winning the next
election" - Huw Edwards, BBC News
------------------------------
Date: 19 Nov 1999 13:52:56 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Fetch Dilbert.
Message-Id: <x7wvrepb3r.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@delanet.com> writes:
A> The reason I prefer /opt over /usr/local is this:
A> $ rm -rf /opt/perl # Poof. All of this package gone.
but then you have to add /opt/perl/bin to your path (and MANPATH,
etc.). that is true for each of the other 3rd party things you build in
/opt. i have seen sysadmins (if you can call them that) with each
package in their own /opt dir and all the attendant noise in the ENV
vars.
A> With /usr/local, you have to browse through /usr/local/bin and figure
A> out which binaries/scripts come with Perl and which don't. Not to mention
A> figuring out which man pages need to disappear.
the man pages sit in /usr/local/lib/perl/*/man. the binaries are a minor
issue. each version usually has a link with its version number in
it. the support scripts are not as version specific IMO (i don't use
most of them).
A> And as an added benefit, for a development version of perl, I can
A> just do:
A> $ ./Configure -Dprefix=/opt/devperl
A> and make/make test/make install the stuff without it overwriting any
A> of the files belong to the stable version of perl.
that is fine for a dev perl. for production i want it in the well known
place of /usr/local.
just another /usr/local/bin/perl hacker,
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 19 Nov 1999 02:48:59 GMT
From: lee.lindley@bigfoot.com
Subject: Re: file descriptors already used when perl starts
Message-Id: <812dqr$r82$1@rguxd.viasystems.com>
g0177325@my-deja.com wrote:
:>Can anyone explain the following:
:> perl -e 'open A, ">&2"; open B, ">&2"; print fileno A, fileno B'
:> 37
:>So, file descriptors 4,5,6 are somehow in use. Why?
Probably because something forgot to close them, but there is
always the possibility of those magic __END__ and __DATA__
filehandles being involved somehow. And don't forget the
script itself. I'm kind of curious myself.
ksh: truss perl -e 'open A, ">&2"; open B, ">&2"; print fileno A,>
execve("/usr/lib/lprgs/perl", 0xFFBEF994, 0xFFBEF9A4) argc = 3
open("/dev/zero", O_RDONLY) = 3
mmap(0x00000000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xFF
3A0000
open("/usr/dt/lib/libsocket.so.1", O_RDONLY) Err#2 ENOENT
open("/usr/openwin/lib/libsocket.so.1", O_RDONLY) Err#2 ENOENT
open("/usr/local/rg/lib/libsocket.so.1", O_RDONLY) Err#2 ENOENT
open("/usr/lib/libsocket.so.1", O_RDONLY) = 7
[snip]
Hmm. The information from truss doesn't really answer it. I would
have expected to see an "open" return 4,5 and/or 6 here. But instead
it goes from 3 to 7. 3 and 7 are both later closed before the
dups from the script itself.
Nevertheless, I cannot remember reading any specification that
guarantees any file descriptor numbers other than 0,1 and 2. The
others are up for grabs. I think that there is a convention that the
next lowest available number is returned, but I don't know of any
guarantees. Anybody familiar with the ANSI C specification willing
to comment? "Just another Larry", didn't you have a hand in that
spec?
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Fri, 19 Nov 1999 09:59:52 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: file descriptors already used when perl starts
Message-Id: <MPG.129f2ff043d051298a23d@nntp.hpl.hp.com>
In article <812dqr$r82$1@rguxd.viasystems.com> on 19 Nov 1999 02:48:59
GMT, lee.lindley@bigfoot.com <lee.lindley@bigfoot.com> says...
...
> Nevertheless, I cannot remember reading any specification that
> guarantees any file descriptor numbers other than 0,1 and 2. The
> others are up for grabs. I think that there is a convention that the
> next lowest available number is returned, but I don't know of any
> guarantees. Anybody familiar with the ANSI C specification willing
> to comment? "Just another Larry", didn't you have a hand in that
> spec?
The concept of the integer file descriptor is part of the Unix I/O
model, but not part of the ANSI/ISO C Standard I/O model. It is
available in Perl because perl is built on the underlying Unix/POSIX-
compliant C library. If that isn't the case, the file descriptors have
to be simulated. (That is just a conjecture, of course.)
I can't find any guarantees about the value of the file descriptor in
open(2) either.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 19 Nov 1999 13:33:38 GMT
From: g0177325@my-deja.com
Subject: Re: file descriptors already used when perl starts
Message-Id: <813jji$k7j$1@nnrp1.deja.com>
In article
<Pine.GSO.4.10.9911181455210.16575-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:
> On Thu, 18 Nov 1999 g0177325@my-deja.com wrote:
>
> > perl -e 'open A, ">&2"; open B, ">&2"; print fileno A, fileno B'
> > 37
> >
> > So, file descriptors 4,5,6 are somehow in use. Why?
>
> $ perl -lwe 'open A, ">&2"; open B, ">&2"; print fileno A, fileno
B'
> 34
>
> Mystery to me. But maybe one of those is the tempfile which holds the
> source from -e.
Likely, yes. I neglected to mention that my test was with 5.004_04.
I now also tried it with 5.005_03 and got your (more sensible) result.
I believe 5.005_03 no longer uses a temp tile for -e scripts. As for
the other two fds, who knows? fileno(DATA) was undefined. Probably
just sloppy C programming...
John.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 19 Nov 1999 13:50:19 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: file descriptors already used when perl starts
Message-Id: <813kir$t5l$1@pegasus.csx.cam.ac.uk>
In article <811o2k$ata$1@nnrp1.deja.com>, <g0177325@my-deja.com> wrote:
>Can anyone explain the following:
>
> perl -e 'open A, ">&2"; open B, ">&2"; print fileno A, fileno B'
> 37
>
>So, file descriptors 4,5,6 are somehow in use. Why?
As various others have remarked, they aren't for me.
But I'll gaze into my crystal ball and guess that you're running on
some flavour of Linux. There is a bug in some versions of glibc
that causes open to allocate a file descriptor other than the lowest
available, explicitly contrary to POSIX and to Linux's own man page.
There was a thread about this recently on p5p - note
that it causes much havoc if you try to close and re-open STDERR etc.
See
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-10/msg00189.html
and followups.
Mike Guy
------------------------------
Date: 19 Nov 1999 13:59:55 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: file descriptors already used when perl starts
Message-Id: <813l4r$dc$1@pegasus.csx.cam.ac.uk>
In article <Pine.GSO.4.10.9911181455210.16575-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:
>On Thu, 18 Nov 1999 g0177325@my-deja.com wrote:
>
>> perl -e 'open A, ">&2"; open B, ">&2"; print fileno A, fileno B'
>> 37
>>
>> So, file descriptors 4,5,6 are somehow in use. Why?
>
> $ perl -lwe 'open A, ">&2"; open B, ">&2"; print fileno A, fileno B'
> 34
>
>Mystery to me. But maybe one of those is the tempfile which holds the
>source from -e.
Shouldn't be. The filehandle will have been closed, since there isn't
a __DATA__. Of course, on modern Perls there isn't a tempfile.
But I get the result '34' even back in perl4.
Mike Guy
------------------------------
Date: Fri, 19 Nov 1999 18:02:49 GMT
From: scott@aravis.softbase.com (Scott McMahan)
Subject: Re: File::Find on Win32 :-( - getit4.pl (0/1)
Message-Id: <dhgZ3.281$AQ2.22013@newshog.newsread.com>
John Armsby (jaws@mindspring.com) wrote:
> I have written a short Perl script to recurse through a Novel
> (windows) directory and return path and file name. Interestingly
> enough "dir /b/s" does the same thing. The good news is that it
> works. The bad news is that long filenames are reduced to the 8.3
> format. SURELY there is a way around this. I am running the latest
> from active state on NT with all the service packs installed.
> Any help would be appreciated.
File::Find works on native Win32 file systems and returns the full
paths, because I've done it and do it every time I weed out unnecessary
backup files (*~, etc) before making a backup and have some
monster long names with spaces and stuff.
So the issue must be in the Novell drivers. It may be impossible to
get "long" filenames over such a connection. This is not a Perl issue,
I don't think.
Scott
http://autoperl.skwc.com Automating Windows With Perl
------------------------------
Date: Wed, 17 Nov 1999 03:04:41 GMT
From: beans@bedford.net (Thunderdust (TomH))
Subject: Re: foreach on a hash within a hash
Message-Id: <38321b04.2006428@news.bedford.net>
$\ = "\n";
$h{a}{w} = 1;
$h{a}{x} = 2;
$h{b}{y} = 3;
$h{b}{z} = 4;
foreach $k1 (keys %h) {
print $k1;
foreach $k2 (keys %{$h{$k1}}) {
print $k2;
print $h{$k1}{$k2};
}
}
On Wed, 17 Nov 1999 03:32:07 GMT, Curtis Jones
<curtisj@BannerFusion.com> wrote:
>What is the best way to go about retrieving a list of the values of a
>hash within a hash?
>
>If I simply have a hash,
>
>%hash;
>$hash{'one'};
>$hash{'two'};
>$hash{'three'};
>
>I can do a:
>
>foreach ( sort keys %hash ) ...
>
>to retrieve each of the values in it, but I can't seem to figure out how
>to do that to a hash that is within a hash...or deeper.
>
>Thanks for any help.
>
>-Curtis
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
Schnoodlewinks-constantly leveling up warrior
Fluffy_the_Fly-lvl.7 warrior (x2-don't ask!)
Flame-QFG5 Paladin
------------------------------
Date: Fri, 19 Nov 1999 14:30:56 GMT
From: "Jim Mosier" <jim.mosier@usa.net>
Subject: Fork Children w/ Expect
Message-Id: <AadZ3.7486$dz1.653555@pm02news>
I have a fully functional program that forks children then runs a set of
instructions depending on the directory the child was instructed to read.
One set of instructions will use Expect to create a telnet session to a
modem pool and send an "AT" and look for an "OK".
All is well and the children die peacefully until the following is done.
$modem = Expect->spawn( "/bin/telnet 1.1.1.1 23" );
The children will die but keep coming back. Since my parent is spawning a
child which spawns a telnet, I'm wondering if Perl is loosing it's mind.
Anyone have similar experience or advice?
Solaris 2.6, Perl 5.004_04, Expect 1.07
------------------------------
Date: Fri, 19 Nov 1999 09:39:29 GMT
From: John Arrowwood <jarrowwx@NOSPAM.home.com>
Subject: Re: Generating pi
Message-Id: <38351AE2.D557CF32@NOSPAM.home.com>
Matt Dale wrote:
> revjack <revjack@radix.net> wrote:
>
> >revjack explains it all:
> >:Anybody ever tool up an algorithm in perl to generate the
> >:digits of pi?
>
> >Um, I mean, an algorithm that will crank out the digits one
> >after another, ad infinitum, without cheating like Abigail.
>
> Try this
>
> 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11....................and so on.
>
> I leave you to work out the perl, this may take a while.
Cool, and easy (took less than 5 minutes to code), but not very
accurate. I wanted to do a similar thing once, but to one million
decimal places. This only works to about 3 decimal places, then loses
out due to rounding errors (most likely). Any other suggestions?
---code---
my $pi = 0;
my $n = 1;
my $sign = 1;
while ( 1 ) {
$pi += 4 / $n * $sign;
$sign *= -1;
$n += 2;
print "$pi \n"; # to see it as it calculates
}
---/code---
------------------------------
Date: 19 Nov 1999 18:50:13 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Generating pi
Message-Id: <814655$q81$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to John Arrowwood
<jarrowwx@NOSPAM.home.com>],
who wrote in article <38351AE2.D557CF32@NOSPAM.home.com>:
> > 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11....................and so on.
> >
> > I leave you to work out the perl, this may take a while.
>
> Cool, and easy (took less than 5 minutes to code), but not very
> accurate. I wanted to do a similar thing once, but to one million
> decimal places. This only works to about 3 decimal places, then loses
> out due to rounding errors (most likely). Any other suggestions?
This one is almost instantaneous:
perl -MMath::Pari=:prec=60,sumalt,Pi -wle
'print sumalt($x, 1, sub { 4/(2*$x - 1)*(-1)**($x+1) } ); print Pi'
3.141592653589793238462643383279502884197169399375105820974944592308078
3.141592653589793238462643383279502884197169399375105820974944592307782
Ilya
------------------------------
Date: Fri, 19 Nov 1999 18:21:06 GMT
From: Surfy <slimy@bigfoot.com>
Subject: Help me read my database please
Message-Id: <8144ec$1i3$1@nnrp1.deja.com>
Hello,
I've been modifying other people's perl scripts for years but I am now
faced with a problem and I have to write a small script myself. The
script must accept a database id number (passed through a form),
retrieve the record from the flatfile pipe-delimited database
corresponding to that id number and then print out an html page based
on the fields in the record. I've figured everything else out, but not
how to retrieve the record from the database. To give you an idea of
what I'm looking for... here's what I want the script to do.
1) Open the pipe-delimited database (which already exists) for reading
2) Look through it until it finds the right record
3) Stop looking once it's found it (each record has a unique id)
4) Split the record into individual variables (not an array)
5) Close the database
Once that happens ... I'm assuming I can just use those variables in
the second half of the script which displays the HTML. That second
half works ... but I have no content cause I can't get the info from
the database.
Thanks VERY MUCH in advance,
Surfy
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 19 Nov 1999 18:37:30 GMT
From: sp00fD <sp00fD@yahoo.com>
Subject: Re: Help me read my database please
Message-Id: <8145da$2cj$1@nnrp1.deja.com>
In article <8144ec$1i3$1@nnrp1.deja.com>,
Surfy <slimy@bigfoot.com> wrote:
> Hello,
>
> I've been modifying other people's perl scripts for years but I am now
> faced with a problem and I have to write a small script myself. The
> script must accept a database id number (passed through a form),
> retrieve the record from the flatfile pipe-delimited database
> corresponding to that id number and then print out an html page based
> on the fields in the record. I've figured everything else out, but
not
> how to retrieve the record from the database. To give you an idea of
> what I'm looking for... here's what I want the script to do.
>
> 1) Open the pipe-delimited database (which already exists) for reading
> 2) Look through it until it finds the right record
> 3) Stop looking once it's found it (each record has a unique id)
> 4) Split the record into individual variables (not an array)
> 5) Close the database
>
> Once that happens ... I'm assuming I can just use those variables in
> the second half of the script which displays the HTML. That second
> half works ... but I have no content cause I can't get the info from
> the database.
>
> Thanks VERY MUCH in advance,
> Surfy
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
I'm quite sure there's a CSV DBI module available. This would be the
way to do it and would leave room to easily move the CSV to a true
database if you decide to do so at a later date. I'm quite sure the
module exists, but I don't know much about it so that will be an
exercise for you. I think there's an article in the latest Perl
Journal about it, unfortunately I don't have it near me.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 19 Nov 1999 09:25:16 -0000
From: "Richard" <richard@avocation.demon.co.uk>
Subject: Help Uploading Files to Web Site
Message-Id: <943003573.18416.1.nnrp-01.d4e489f6@news.demon.co.uk>
The script below is supposed to upload an image file from a local PC to the
web site. It creates the file on the server but it's of zero bytes!!
The script doesn't appear to copy anything from the source file into the
destination file........can anyone help or point me in the right direction
please?
#!/usr/local/bin/perl5 -w
use lib $0 =~ m#(.+)[/\\]#;
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
print header();
print start_html("File Upload Example");
print strong("Version "),$CGI::VERSION,p;
print h1("File Upload Example"),
'',
strong(""),
p,
'',cite(''),'';
@types = ('count lines','count words','count characters');
# Start a multipart form.
print start_multipart_form(),
"Enter the file to process:",
filefield('filename','',45),
br,
checkbox_group('count',\@types,\@types),
p,
reset,submit('submit','Process File'),
endform;
# Process the form if there is a file name entered
if ($file = param('filename')) {
$tmpfile=tmpFileName($file);
$mimetype = uploadInfo($file)->{'Content-Type'} || '';
print hr(),
h2($file),
h3($tmpfile),
h4("MIME Type:",em($mimetype));
my($lines,$words,$characters,@words) = (0,0,0,0);
while (<$file>) {
$lines++;
$words += @words=split(/\s+/);
$characters += length($_);
}
close $file;
grep($stats{$_}++,param('count'));
if (%stats) {
print strong("Lines: "),$lines,br if $stats{'count lines'};
print strong("Words: "),$words,br if $stats{'count words'};
print strong("Characters: "),$characters,br if $stats{'count characters'};
} else {
print strong("No statistics selected.");
}
}
# -------Richards additions
$filename = "Cabbage.gif";
$UPLOAD_PATH = "";
$UPLOAD_FILE = $UPLOAD_PATH.$filename;
$bytesread=1;
print "FILE NAME: $UPLOAD_PATH$filename<br>";
# Copy a binary file to somewhere safe
open (OUTFILE,">$UPLOAD_FILE") or die "Could not open output $UPLOAD_FILE
file";
binmode(OUTFILE);
#---->The line below does the transfer but it doesn't seem to kick in.
while ($bytesread >0){
$bytesread=0;
read($file,$buffer,1024) or die "Cant write to the $file file";
print "Filname: $filename, Buffer: $buffer<BR><BR>";
print OUTFILE $buffer;
}
print "Finished - Filname: $filename, Buffer: $buffer<BR><BR>";
close $filename;
# ------End of Richards additions
Any help very gratefully recevied,
Thanks,
Richard.
------------------------------
Date: 19 Nov 1999 10:47:13 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Help Uploading Files to Web Site
Message-Id: <38352ab1_1@newsread3.dircon.co.uk>
Richard <richard@avocation.demon.co.uk> wrote:
> The script below is supposed to upload an image file from a local PC to the
> web site. It creates the file on the server but it's of zero bytes!!
>
> The script doesn't appear to copy anything from the source file into the
> destination file........can anyone help or point me in the right direction
> please?
>
Strangely a colleague of mine was caught by this slef same example in
exactly the same way yesterday - The original code uses up the filehandle
and then closes it - you are then reading from a closed filehandle
in the bit you added. Cut all that other stuff out and try again.
/j\
--
"When the boys in the playground found out that I had a potentially
fatal peanut alergy they would shove me up against a wall and make me
play Russian roulette with a bag of Revels" - Milton Jones
------------------------------
Date: Fri, 19 Nov 1999 15:43:37 +0800
From: "LIN, Yong" <p146046183@ntu.edu.sg>
Subject: Help: 501 Protocol error
Message-Id: <3834FFA9.AC4A5D45@ntu.edu.sg>
Hi, friends,
I installed Apache HTTP server (1.3.9) and Perl
Perl-5.00503-6 in my Linux box. I setup the Apache can be
run CGI program. Finally, I wrote a CGI (using perl)
program and want to execute it in browser. But, I got an
error message:
An Error Occurred
501 Protocol scheme 'http' is not supported
What's the error message mean? How can I solve the
problem? Thanks for any help.
PS: In my CGI program, I used LWP, HTTP, URI.
LIN, Yong
------------------------------
Date: Fri, 19 Nov 1999 06:52:17 -0800
From: Tim Westlake <tim.westlakeNOtiSPAM@myremarq.com.invalid>
Subject: Re: How do I get a list of users in an NT domain?
Message-Id: <000b8d9b.15997949@usw-ex0101-008.remarq.com>
In article <3833DCD1.5BAF29C4@patriot.net>, wintermute
<carvdawg@patriot.net> wrote:
> Use the Win32::Lanman module. Version 1.04 fixed some minor bugs,
Where can I get it from? I looked on CPAN and it doesnt appear to be
there.
rgds
Tim
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Fri, 19 Nov 1999 10:23:18 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: How to make the comparable also hashable?
Message-Id: <812c9m$jm9@netnews.hinet.net>
Martien wrote:
> It is not clear to me what you want.
package A;
use overload cmp =>\&compare;
sub new { my($class,$value)=@_; bless \$value }
sub compare {
my($self,$peer,$reverse)=@_;
$reverse? abs($$peer)<=>abs($$self): abs($$self)<=>abs($$peer);
}
package main;
my $a=new A(1);
my $b=new A(-1);
print 'yes, $a eq $b' if $a eq $b; # get yes
# code below is psudo
my %hash;
$hash{$a}=1;
$hash{$b}=2; # $b eq $a, so '2' will replace '1'
print $hash{$a}; # I need to get '2' here
This is what I want.
I redefined package A's comparison.
Suppose $a 'eq' $b by my definition, I want them
to be hashed together.
print $hash{$a};
will get '2', not '1', because in
$hash{$b}=2;
$b is treated 'eq' $a, so $hash{$a}='1' will be
replaced by '2' here
In my real case, the package is easy to redefine comparison
but difficult to string-ify.
Thanks
John Lin
P.S. Sorry, our news server broke,
so I can only 'follow up' my own message.
------------------------------
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 1430
**************************************