[8728] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2345 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 17 02:07:24 1998

Date: Thu, 16 Apr 98 23:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 16 Apr 1998     Volume: 8 Number: 2345

Today's topics:
        Attempt to speed up rand() (Mark Waterous)
    Re: cgi using perl (Abigail)
    Re: CLPM CONTENT POLICE (was info on cookies) <rjk@coos.dartmouth.edu>
    Re: Hide or Encrypt perl source code (Martin Vorlaender)
    Re: How to call an unix rsh in perl <dmwaff@erols.com>
    Re: How to execute more than one command via System (Jason Gloudon)
    Re: Image instead of button in Perl Script (Abigail)
        multi-lingual program in perl (LMK)
    Re: Multi-tasking/threading <zenin@archive.rhps.org>
    Re: Perl library for INI file <rootbeer@teleport.com>
        perl tutorial (WAS Re: General Rudeness, e.g. Re: Need  <caw@belloc.med.monash.edu.au>
    Re: perl tutorial (WAS Re: General Rudeness, e.g. Re: N <rootbeer@teleport.com>
    Re: putc? (Abigail)
    Re: putc? (Andrew M. Langmead)
    Re: rand($.) (was wc-l in Perl) <jdf@pobox.com>
    Re: rand($.) (was wc-l in Perl) <rjk@coos.dartmouth.edu>
    Re: rand($.) (was wc-l in Perl) (Martin Vorlaender)
    Re: Recursive Calls in Perl ? (Jason Gloudon)
        regular expression question (John Cartwright)
    Re: regular expression question <jdf@pobox.com>
    Re: regular expression question <rjk@coos.dartmouth.edu>
    Re: Server Side Include (Abigail)
    Re: test for list membership - searching for the right  <rootbeer@teleport.com>
    Re: unix commands in a perl (Martien Verbruggen)
    Re: Which Win32 Perl dennis_marti@yahoo.com
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 17 Apr 1998 05:19:04 GMT
From: mail@silas.hypermart.net (Mark Waterous)
Subject: Attempt to speed up rand()
Message-Id: <35369f9a.7328221@news.bctel.ca>

	I have a short script that I wrote, mostly as a quick practice
of my perl, but what it does is it loads a random page, depending on
the result returned by the rand() function. The script is short, and
looks like this:

--[begin default.pl]--
#!/usr/local/bin/perl -w
use diagnostics;
use strict;

my $count = 2;
my $page_load = int(rand($count));

print "Content-type: text/html\n\n";

open (FILE, "$page_load") || die "Couldn't open file [".$page_load."]
Reason: $!"";
  while (<FILE>) {
   print "$_";
  }
close (FILE) || die "Couldn't close file [".$page_load."] Reason: $!";


--[end default.pl]--

	What I am attempting to do now, though I don't know if it's
possible, is to speed up the process a bit. It delays for just over a
second before returning a page, and though this isn't too much, if it
can be gotten around, I would like to do it. Yes, I am looking through
the documentation for any other related material, but I haven't found
any yet.



_________________________________
Mark Waterous - Silas Productions Online

"Your entrance to a world of information..."
                          http://silas.hypermart.net/


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

Date: 17 Apr 1998 03:58:41 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: cgi using perl
Message-Id: <6h6k1h$q28$2@client3.news.psi.net>

Yeung Mau Yuen Terence (terencey@dns1.chevalier.net) wrote on MDCXC
September MCMXCIII in <URL: news:35378788.0@news.chevalier.net>:
++ 
++ 
++ failure:for host xxx.xxx.xxx.xxx trying to POST /shell-cgi/xxx.pl,
++ cgi-parse-output reports: the CGI program c:\perl\bin\per.exe did not
++ produce a valid header (name without value: got line "<html>")....


There's no Perl specific aspect in your question. It's not more on topic
here than it is in rec.furniture or rec.pets.rodents because you program
sitting in a chair and your computer has a mouse.


Ask in the CGI group. Or better, read the FAQ. I'm pretty sure your
question is answered there.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Thu, 16 Apr 1998 23:59:24 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: CLPM CONTENT POLICE (was info on cookies)
Message-Id: <3536D39E.2A936933@coos.dartmouth.edu>

Andrew F. Lee wrote:
> 
> In my humble opinion, Perl and CGI are commmon companions.  I think that
> CGI questions coming from a Perl programmer ought to be welcome on
> comp.lang.perl.misc (misc being short for miscellaneous, from the Latin
> miscellus -- mixed).

Then I suppose Perl and Unix are common companions too.  Perhaps we should
discuss CGI in clpm, and Perl in the Unix newsgroups.  And Unix in the
hardware newsgroups.  And hardware in the retail distributor newsgroups.  And...

> As a Perl programmer, I do not usually come to clpm questions about syntax
> so much as questions about semantics.  Apologies to those who are studying
> Perl in a vacuum with no intention of ever writing applications.

I didn't realize people who used Perl for purposes other than writing CGI
programs were studying in a vacuum, with no intention of ever writing
applications.  Get over yourself.

I've written approximately one CGI script in Perl, and worked on approximately
one other.  On the other hand, I've used Perl for lots and lots of tasks which
have nothing to do with CGI.

> My point:  If you have something useful to say, please do.  If you have
> just had too much caffeine, please refrain from posting pointless and
> sniveling comments (unless they are funny).

Okay then.

Q: How many newbies does it take to screw in a lightbulb?

A: I don't know.  Let's go ask in comp.lang.perl.misc.


-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 17 Apr 1998 05:21:55 +0200
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Hide or Encrypt perl source code
Message-Id: <3536cad3.524144494f47414741@radiogaga.harz.de>

John Porter (jdporter@min.net) wrote:
: Stuart McDow wrote:
: > "Grinch" <grinch@whoville.com> writes:
: > > the only way to run a Perl script on a Win32 machine would be to
: > > install the entire Perl-Win32 distribution.
: > Is this really such a bad thing? The core distribution (5.004_2)
: > without the man directory is only 10MB or so. 

: "only 10MB".

: I wish 10MB were a mere pittance to everyone (such as our
: marketers) as it is to you.

: I commercial project I'm on had a total installation footprint 
: of about 4 meg until I suggested (and started) using perl.
: Now it's 14 meg.  Do you think that's easy to justify?

Show them the footprint of any Microsoft product....

As an aside: Can't you cut down the size by evaluating just which modules
you need? I can't believe you need a complete distribution...

cu,
  Martin
  who just spent 150 MB to get VC++ 5 onto his computer
--
                          | Martin Vorlaender | VMS & WNT programmer
 Ceterum censeo           | work: mv@pdv-systeme.de
 Redmondem delendam esse. |       http://www.pdv-systeme.de/users/martinv/
                          | home: martin@radiogaga.harz.de


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

Date: Fri, 17 Apr 1998 01:14:19 -0400
From: "David Waffen" <dmwaff@erols.com>
Subject: Re: How to call an unix rsh in perl
Message-Id: <6h6ocj$elp$1@winter.news.erols.com>

I have a similar experience.

I can't rcp or rsh to a remote host!

I open a LOG file on machine "A" and write to that file.  Later in the
script the LOG file needs to be remote copied to another host where the
user's home directory sits.
>From the command line rcp works great, BUT rsh and rcp I have never been
able to use with the system command.
ie... system("rcp -rp /Admin/Boneyard/$user/.RM_USER.LOG
somesrv:/Users/<home>");

It goes out to the remote host and looks like it just does a touch.  The log
file on the remote host is empty, zero size.  The guts never get
transferred.  Like you, I need to rsh later and gnutar the home directory to
move it back to my server to archive in my Boneyard.

Any help would be much appreciated.
david.waffen@mci.com or dmwaff@erols.com

Ying Peng wrote in message <35367F34.C5873ADA@cae.cig.mot.com>...
>Dear Folks,
>
>I am very new in the Perl world so may ask some dumb questions here.
>
>Here is my question:
>
>I want to use the following unix command in perl:
>
>rsh B "/net/A/home/peng/1.tar /home/daok" <--Has to use "
>
>I only know I can use the "system" function to call unix commands but
>the problem is double quote. the system function requires the double
>quote also such as:
>
>system("ls");
>
>Cannot use system('ls') or system(`ls`) as I observed so far.
>
>Thanks very much for your great thought in advance.
>
>--Ying
>
>Motorola CAE/CIG/CAM support group




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

Date: Fri, 17 Apr 1998 04:21:56 GMT
From: jgloudon@manitoba.bbn.com (Jason Gloudon)
Subject: Re: How to execute more than one command via System
Message-Id: <slrn6jdm1t.3oa.jgloudon@manitoba.bbn.com>

Greg Gershowitz <gregg@charlotte.computex.com> wrote:
 .
>>You might alternatively consider doing away with the system()
>>altogether by using File::Copy or one of the other alternatives
>>advocated here a little while ago (better check DejaNews for the full
>>SP on that)
>
>   The problem with the File:: that I have, is that it doesn't seem to
>support concatenating files, which is what I'm trying to do.

If you open the output file yourself you can call File::Copy with the
filehandle you opened the file with, and it will append to the file.
You'd have to take care to open the file in binary mode.

-- 
Jason Gloudon


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

Date: 17 Apr 1998 03:59:41 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Image instead of button in Perl Script
Message-Id: <6h6k3d$q28$3@client3.news.psi.net>

Brad Atkins (batkins@age.net) wrote on MDCXC September MCMXCIII in
<URL: news:3536AC74.62E803B8@age.net>:
++ I've been trying to get an image instead of a normal form button in a
++ web based email client. The problem is, that with certain functions
++ (everything except logging in) the Script does not fetch the datum.

Any Perl question you want to ask?


Abigail
-- 
perl -wle '$_ = 1; (1 x $_) !~ /^(11+)\1+$/ && print while $_ ++'


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

Date: 17 Apr 1998 04:14:28 GMT
From: lmk@moon.csc.cuhk.edu.hk (LMK)
Subject: multi-lingual program in perl
Message-Id: <6h6kv4$r2d@eng-ser1.erg.cuhk.edu.hk>

Hi all,

According to some guidelines, writing multilingual programs should 
put user interface messages in resource files. Now, I wanna know which
place is the best to store such pieces of information in perl.

Resource file as Package? Object Class? Simple file? DBM?


-- 
[LMK :P]

 < EMail : lmk@moon.csc.cuhk.edu.hk >



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

Date: 17 Apr 1998 04:04:40 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: Multi-tasking/threading
Message-Id: <892786297.361860@thrush.omix.com>

Sleep <mhchau@cse.cuhk.edu.hk> wrote:
: Hail , I want to ask : Can Perl multi-threading as what java does?
: Any reference about that ?

	The next release (5.005) has threads.  If you're into pain, you can
	start playing with the betas available on CPAN.

	However, if you don't understand non-thread methods of passing
	data, correct use of select(), shared memory, event loops, etc then
	threads are likely to be nothing more then the crutch they are in
	Java for bad programmers.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Fri, 17 Apr 1998 04:17:37 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: James Lim <huameng@dbs.com.sg>
Subject: Re: Perl library for INI file
Message-Id: <Pine.GSO.3.96.980416211723.29515L-100000@user2.teleport.com>

On Fri, 17 Apr 1998, James Lim wrote:

> Is there any library for reading/writing INI file format out there?

If there's a module which does what you want, it should be listed in
the module list on CPAN. If you don't find one to your liking, you're
welcome and encouraged to submit one! :-)  Hope this helps!

    http://www.perl.org/CPAN/
    http://www.perl.com/CPAN/

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 17 Apr 1998 13:53:15 +1000
From: "Chris Wright" <caw@belloc.med.monash.edu.au>
Subject: perl tutorial (WAS Re: General Rudeness, e.g. Re: Need a web login script)
Message-Id: <6h6jnf$3b0$1@towncrier.cc.monash.edu.au>


Abby Franquemont wrote in message <6h5lfl$r6d$1@ucan.foad.org>...
>[snip]
>On a perl-related note, now that I'm back to a perl-heavy thing to do,
>I was out piling up perl-related bookmarks and reference things as is
>my wont and I have to say the leeds.ac.uk tutorial is really well done.
>I don't think it was around last time I was piling up reference material,
>and it's really a standout as far as I'm concerned. </two-cents>
>
>ObURL: http://agora.leeds.ac.uk/Perl/start.html but then I'd imagine
>everyone knows that.


As a newcomer to Perl, I had a look at this tutorial. I found the following
discussion of "local" variables...


sub inside{ local($a, $b);   # Make local variables
 ($a, $b) = ($_[0], $_[1]); # Assign values $a =~ s/ //g;   # Strip spaces
from
 $b =~ s/ //g;   #   local variables
 ($a =~ /$b/ || $b =~ /$a/); # Is $b inside $a     #   or $a inside $b?}
&inside("lemon", "dole money");  # true


This could be VERY confusing...Isn't he confusing "local" and "my" one
changing the scope of a variable and the other providing a variable of local
scope?

I wouldn't recommend this tutorial to a fellow newbie.

cheers

chris






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

Date: Fri, 17 Apr 1998 04:35:37 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Chris Wright <caw@belloc.med.monash.edu.au>
Subject: Re: perl tutorial (WAS Re: General Rudeness, e.g. Re: Need a web login script)
Message-Id: <Pine.GSO.3.96.980416212503.29515O-100000@user2.teleport.com>

On Fri, 17 Apr 1998, Chris Wright wrote:

> Abby Franquemont wrote in message <6h5lfl$r6d$1@ucan.foad.org>...

> >ObURL: http://agora.leeds.ac.uk/Perl/start.html but then I'd imagine
> >everyone knows that.
> 
> 
> As a newcomer to Perl, I had a look at this tutorial. I found the following
> discussion of "local" variables...
> 
> 
> sub inside{ local($a, $b);   # Make local variables
>  ($a, $b) = ($_[0], $_[1]); # Assign values $a =~ s/ //g;   # Strip spaces
> from
>  $b =~ s/ //g;   #   local variables
>  ($a =~ /$b/ || $b =~ /$a/); # Is $b inside $a     #   or $a inside $b?}
> &inside("lemon", "dole money");  # true

Let's reformat that:

> sub inside {
>     local($a, $b);   # Make local variables
>     ($a, $b) = ($_[0], $_[1]); # Assign values
>     $a =~ s/ //g;   # Strip spaces from
>     $b =~ s/ //g;   #   local variables
>     ($a =~ /$b/ || $b =~ /$a/); # Is $b inside $a
>     #   or $a inside $b?
> }
> &inside("lemon", "dole money");  # true

> This could be VERY confusing...Isn't he confusing "local" and "my" 

Not that I see. He's not using my() at all, is he? But it's not great
code, either. I would have at least one suggestion to improve every line
of that sub. And I wouldn't call it in a void context. :-)

> I wouldn't recommend this tutorial to a fellow newbie.

Check. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 17 Apr 1998 04:15:17 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: putc?
Message-Id: <6h6l0l$q85$1@client3.news.psi.net>

matt dick (dick@ssd.comm.mot.com) wrote on MDCXC September MCMXCIII in
<URL: news:6h6e90$l7v@tako.wwa.com>:
++ Okay, I want to print a single character without a \n.  I want to 
++ repeat this behavior in a while loop, once every 30 seconds while
++ I monitor a file's status.  I want to hold off printing a carriage
++ return until I am out of the while loop.
++ 
++ Problem is, [s]print[f] buffers the stream until the \n.  I asked
++ my Blue Camel and my Blue-black Leopard and neither knows the 
++ answer, the Camel tells me that if I want to do a putc I should
++ use print.  Print is apparently not the answer, however.


Read perlvar, about $|


Abigail
-- 
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT


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

Date: Fri, 17 Apr 1998 04:23:07 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: putc?
Message-Id: <ErJIuJ.GEo@world.std.com>

dick@ssd.comm.mot.com (matt dick) writes:

>Okay, I want to print a single character without a \n.  I want to 
>repeat this behavior in a while loop, once every 30 seconds while
>I monitor a file's status.  I want to hold off printing a carriage
>return until I am out of the while loop.

>Problem is, [s]print[f] buffers the stream until the \n.  I asked
>my Blue Camel and my Blue-black Leopard and neither knows the 
>answer, the Camel tells me that if I want to do a putc I should
>use print.  Print is apparently not the answer, however.

The C function putc() doesn't do what you might think it does. It
justs writes a single character to the specified stdio output stream,
it doesn't affect buffering at all.

Most of perl's I/O operators (for most perl configurations) are
implemented based on the standard C stdio library. Most
implementations of this library by default buffer output line by line
if the output device is a terminal, and buffer by larger blocks if the
output device is not.

But perl has a method that allows you to tell it to automatically
flush the buffer of a filehandle after each output operation. It is
tied to the magic variable $|. Giving it a non-zero numeric value will
set the currently selected filehandle to be command buffered. A
numeric value of zero will leave it to the default characteristics.

But its tough to autoflush a filehandle other than the currently
selected one:

my $oldfh = select(FILEHANDLE);
$|=1;
select($oldfh);

Or maybe you want to design your code to be more on the readable
side. In that case, an alternate way of setting a filehandle to
command buffering is to use the Object Oriented methods in the
IO::File module.

use IO::File;
STDOUT->autoflush(1);

It does the same thing, its just wrapped up in a prettier package. But
on the other hand, it verbose, and it has the overhead of loading in a
module that you might not otherwise need. So take your pick:

perl -e '$|=1;print "." and sleep 257 while $count++ < 10;print "\n"'

(and I'm sure its obvious to the people who do a better job of keeping
up with the traffic in comp.lang.perl.misc, the answer hasn't changed
since this morning when I wrote my last article explaining buffering.)
-- 
Andrew Langmead


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

Date: 17 Apr 1998 00:34:24 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: rand($.) (was wc-l in Perl)
Message-Id: <emyxnh9b.fsf@mailhost.panix.com>

tmornini@netcom.com (Tom Mornini) writes:

> In a discussion about picking a random line from a file Tom Phoenix wrote:

> >    while (<FILE>) {
> >        $line = $_ if rand($.) <= 1;
> >    }
> 
> My question is: Why doesn't this hopelessly bias the randomness towards
> the beginning of the file, when rand($.) would be more likely to be <= 1?

The first line will always be picked.  The second line will be picked
exactly %50 of the time (since rand(2) will be less than or equal to 1
%50 of the time).  Therefore, in a two-line file, each line has the
same chance of being picked.  Line three will be picked one-third of
the time, giving lines 1 and 2 a 2/3 chance of remaining picked (and
since each had a %50 chance to remain picked, the net odds are 1/3 a
piece).

Formally:

The chance of line m remaining picked out of n lines total, where p(x)
is the probability of line x being picked (and happens to be the
function 1/x) is equal to

  p(m) (1-p(m+1)) (1-p(m+2)) ... (1-p(n-1)) (1-p(n))

= 1/m (1-1/(m+1)) (1-1/(m+2)) ... (1-1/(n-1)) (1-1/n)

= 1/m (m/(m+1)) ((m+1)/(m+2)) ... ((n-2)/(n-1)) ((n-1)/n)

= 1/n 

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY 
Who was seriously about to run ispell to catch logic errors.


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

Date: Fri, 17 Apr 1998 00:46:14 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
To: TomMornini <tmornini@netcom.com>
Subject: Re: rand($.) (was wc-l in Perl)
Message-Id: <3536DE9A.4A6F7279@coos.dartmouth.edu>

[posted and mailed]

Tom Mornini wrote:
> 
> In a discussion about picking a random line from a file Tom Phoenix wrote:
> 
> >    open FILE, $name or die "Can't read '$name': $!";
> >    while (<FILE>) {
> >        $line = $_ if rand($.) <= 1;
> >    }
> >    print "One randomly-selected line is $line";
> 
> My question is: Why doesn't this hopelessly bias the randomness towards
> the beginning of the file, when rand($.) would be more likely to be <= 1?
> 
> I ran it on a 112,000 line file over 100 iterations, and it seems that
> it biases towards the end of the file, which also makes sense, since earlier
> selections will be written over by later selections...

Actually, it's not biased towards either end of the file.  100 iterations is
not sufficient for a statiscally significant result.

If n is the number of lines, and m is a specific line number, then the
probability that line m is the result [call it P(M)] is the probability that
line m is selected [P(m)] multiplied by the probability that no subsequent
lines are selected [P(n)].

P(m) = 1/m
P(n) = (1 - 1/(m+1)) * (1 - 1/(m+2)) * ... * (1 - 1/(n-1)) * (1 - 1/n)
     = m/(m+1) * (m+1)/(m+2) * ... * (n-2)/(n-1) * (n-1)/n
     = (m * m+1 * ... * n-2 * n-1) / (m+1 * m+2 * ... * n-1 * n)
     = m/n
P(M) = (1/m) * (m/n)
     = 1/n

Thus, every line has an equal probability of being the resulting line.


> If fact, I don't believe this code even guarantees that a line is picked!

rand(1) is always less than or equal to 1, no?

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 17 Apr 1998 06:31:24 +0200
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: rand($.) (was wc-l in Perl)
Message-Id: <3536db1c.524144494f47414741@radiogaga.harz.de>

Tom Mornini (tmornini@netcom.com) wrote:
: In a discussion about picking a random line from a file Tom Phoenix wrote:

: >    open FILE, $name or die "Can't read '$name': $!";
: >    while (<FILE>) {
: >        $line = $_ if rand($.) <= 1;
: >    }
: >    print "One randomly-selected line is $line";

: My question is: Why doesn't this hopelessly bias the randomness towards
: the beginning of the file, when rand($.) would be more likely to be <= 1?

: I ran it on a 112,000 line file over 100 iterations, and it seems that
: it biases towards the end of the file, which also makes sense, since earlier
: selections will be written over by later selections...

: If fact, I don't believe this code even guarantees that a line is picked!

rand(1) <= 1, so - if nothing else - line 1 is picked.

: Was there a typo? I'd guess that I'm missing something here... :-)

Let there be n lines.

The probability for the last line to be picked is (rand(n) <= 1), that's 1/n.

The probability for the next to last line to be picked is (rand(n-1) <= 1),
that's 1/(n-1), minus the probability that it's overwritten by the last
line, so it's 1/(n-1) - 1/n = 1/n.

 ...

The probability for the k-th line to be picked is 1/(n-k), minus the
probability that it's overwritten by any of the following lines, so it's
1/(n-k) - k * 1/n = 1/n.

cu,
  Martin
--
                          | Martin Vorlaender | VMS & WNT programmer
 Ceterum censeo           | work: mv@pdv-systeme.de
 Redmondem delendam esse. |       http://www.pdv-systeme.de/users/martinv/
                          | home: martin@radiogaga.harz.de


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

Date: Fri, 17 Apr 1998 04:39:50 GMT
From: jgloudon@manitoba.bbn.com (Jason Gloudon)
Subject: Re: Recursive Calls in Perl ?
Message-Id: <slrn6jdn3f.3oa.jgloudon@manitoba.bbn.com>

Andrew F. Lee <andrewf@cp.pathfinder.com> wrote:
 .
>I missed the original post :(
>
>My (related) question is:  Does Perl do tail recursion?  (And what the
>heck is tail recursion anyway?)

You asked those questions in the wrong order.

>
>The following is an example from "Effective Perl Programming" by Joseph
>Hall and Randal Schwartz:  (Buy it! Read it! Carry it close!) 
>
>#!/usr/local/bin/perl
>sub count_recurse {
>	local *DIRH;
>	my ($file_count_ref, $dir_count_ref, $dir_name) = @_;
>	$$dir_count_ref++;								# count cwd
>	opendir DIRH, $dir_name or die "Couldn't open $dir_name: $!";
>	my @dir = readdir DIRH;

>	close (DIRH);
   ^^^^^
This must have been closedir ?

-- 
Jason Gloudon


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

Date: Thu, 16 Apr 1998 21:34:55 -0600
From: jcartwright@wans.net (John Cartwright)
Subject: regular expression question
Message-Id: <jcartwright-1604982134560001@usm-40-12.wans.net>

Hello All,

I'm trying to build a regular expression that will return only the
signifigant digits to the right of the decimal point.  For instance, if my
value is "1.01200", what I would like to get back is "012".  Although I've
tried a number of alternatives, I was using something like:

$a = "1.01200";
$a =~ s/^(\d+\.) (\d+)0+$/$2/;

unfortunately, this returns the whole number "1.012".  Can someone help me out?

Thanks!

--john


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

Date: 17 Apr 1998 00:48:06 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: regular expression question
Message-Id: <btu1ngmh.fsf@mailhost.panix.com>

jcartwright@wans.net (John Cartwright) writes:

> $a = "1.01200";
> $a =~ s/^(\d+\.) (\d+)0+$/$2/;
                 ^^^
> unfortunately, this returns the whole number "1.012".  Can someone
> help me out?

I'm not sure what you mean by "returns."  If you mean that $a contains
"1.012" after this operation, then your perl is broken, since that
regex shouldn't match at all.  Notice that space between the closing
paren and the opening paren?  Since there are is no space in your
bound string, there's no match.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: Fri, 17 Apr 1998 00:57:46 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
To: John Cartwright <jcartwright@wans.net>
Subject: Re: regular expression question
Message-Id: <3536E14F.9C23EE38@coos.dartmouth.edu>

[posted and mailed]

John Cartwright wrote:
> 
> $a = "1.01200";
> $a =~ s/^(\d+\.) (\d+)0+$/$2/;
> 
> unfortunately, this returns the whole number "1.012".  Can someone help me out?

[Are you sure it doesn't 'return' "1.01200"?]

Probably because your regex doesn't match your target string, so no
substitution is being performed at all.

What's that space doing there?

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 17 Apr 1998 03:56:20 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Server Side Include
Message-Id: <6h6jt4$q28$1@client3.news.psi.net>

Bob Trieger (sowmaster@juicepigs.com) wrote on MDCXC September MCMXCIII
in <URL: news:3536B981.7B3D@juicepigs.com>:
++ Abigail wrote:
++ 
++ > SSI is *not* HTML.
++ 
++ Oh yeah. Show me an example of SSI used outside of HTML. 


Show me an HTML DTD mentioning SSI directives.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Fri, 17 Apr 1998 04:19:39 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Chris Wright <caw@belloc.med.monash.edu.au>
Subject: Re: test for list membership - searching for the right idiom
Message-Id: <Pine.GSO.3.96.980416211915.29515M-100000@user2.teleport.com>

On Fri, 17 Apr 1998, Chris Wright wrote:

> What's the right way to test for list membership in a one-off way.

Use a foreach (or similar) loop. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 17 Apr 1998 04:23:00 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: unix commands in a perl
Message-Id: <6h6lf4$3td$1@comdyn.comdyn.com.au>

In article <35360897.506F@se.bel.alcatel.be>,
	Inge Soetens <soetensi@se.bel.alcatel.be> writes:
> Hi,
> 
> how can I execute some normal UNIX-commands from a perl script ?
> 
> I tried to use "system" and "exec",
> but something seems to go wrong.
[SNIP]
>    exec "/usr/bin/chmod -f 0755 $line" ;
[SNIP]

> The code is executed until it arrives the "exec" statement.
> There it stops.

Have you read the documentation for exec?

#perldoc -f exec
The exec() function executes a system command I<AND NEVER RETURNS> -
use system() instead of exec() if you want it to return.

It's there. Capitalised.

Martien

PS. perl has a builtin chmod. perldoc -f chmod
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | We are born naked, wet and hungry. Then
Commercial Dynamics Pty. Ltd.       | things get worse.
NSW, Australia                      | 


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

Date: Fri, 17 Apr 1998 00:31:13 -0600
From: dennis_marti@yahoo.com
Subject: Re: Which Win32 Perl
Message-Id: <6h6pf2$dou$1@nnrp1.dejanews.com>

In article <35360229.4500@ndirect.co.uk>,
  msergeant@ndirect.co.uk wrote:

> Unless you want to work with IIS [snip]

Does anybody really _want_ to work with that crap?

A little more on topic... I was recently asked to look at a
script that had been ported from Unix to NT and was causing
problems. By switching from Activestate Perl to the GS 5.004_02
binary I was able to delete the 'ported' script and use the
same code on both platforms. It's nice when the right solution
is less work. I recommend the standard (One True?) Perl.

Dennis

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2345
**************************************

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