[9670] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3262 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 27 12:27:57 1998

Date: Mon, 27 Jul 98 07:10:10 -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           Mon, 27 Jul 1998     Volume: 8 Number: 3262

Today's topics:
    Re: -e glob $filename returns true and false in identic <John.Adams@BentonvilleAR.ncr.com>
    Re: ? about binmode() behavior (M.J.T. Guy)
    Re: ? about binmode() behavior <REPLY_TO_damonbrent@earthlink.net>
        Arrays n Patterms <se96ms@english.iielr.dmu.ac.uk>
    Re: Arrays n Patterms (Matthew Bafford)
    Re: Arrays n Patterms (M.J.T. Guy)
    Re: Arrays n Patterms <zenin@bawdycaste.org>
    Re: Arrays n Patterms <quednauf@nortel.co.uk>
    Re: Arrays n Patterms (Abigail)
        Compiling Perl 5.00[45] under AIX 4.2.1.0 (Daniel R Ehrlich)
    Re: Compiling Perl 5.00[45] under AIX 4.2.1.0 <NETtoyeur@usa.net>
    Re: getting  the binary represenation of a number <jhi@alpha.hut.fi>
    Re: having problems reading STDIN <REPLY_TO_damonbrent@earthlink.net>
        How can I get the name of the current subroutine ? <tzahi@tase.co.il>
    Re: If statement does not compare correctly <quednauf@nortel.co.uk>
        launching programs using CGI and Perl Win 32 creiner@my-dejanews.com
        perl and setuid via WEB (apache) <berni@ping-net.de>
    Re: PLEASE HELP: Simple ascii to binary script <nguyend7@egr.msu.edu>
    Re: Problem with random numbers (M.J.T. Guy)
    Re: Problem with random numbers (Mike Stok)
    Re: Reacting to 1 of 10 or so possible values.... Need  (M.J.T. Guy)
    Re: Recent Secret Government Experiments Killing People (-)
    Re: Recent Secret Government Experiments Killing People <davidmcg@cqm.co.uk>
    Re: Simple (I hope) Apache/NT/Perl question (Ivan Fernandez Lobo)
    Re: struggling with date (M.J.T. Guy)
    Re: struggling with date (I.J. Garlick)
    Re: struggling with date (I.J. Garlick)
        Submit only Once <persoft@concentric.net>
    Re: Unable to get REMOTE_HOST (-)
    Re: Y2K problem in PERL with localtime() <qdtcall@esb.ericsson.se>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Mon, 27 Jul 1998 07:01:05 -0500
From: John Adams <John.Adams@BentonvilleAR.ncr.com>
Subject: Re: -e glob $filename returns true and false in identical cases
Message-Id: <35BC6C01.21E4@BentonvilleAR.ncr.com>

Tom Phoenix wrote:
> 
> On Thu, 23 Jul 1998, John Adams wrote:
> 
> > chdir("/home/data/archives/.inventory/");
> 
> Check the return value from this call; it may be failing.

Now is chdir("/home/data/archives/.inventory/") or die "could not
chdir";

> > open(LOOKAME,">/tmp/lookame");
> 
> Even when your script is "just an example" (and perhaps especially in that
> case!) you should _always_ check the return value after opening a file.

Now is open(LOOKAME,">/tmp/lookame") or die "could not open";

The output is unchanged. What the heck is going on in the -e glob
filename statement that is screwing up the outer loop?

	John A
	...still puzzled, still speaking only for himself


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

Date: 27 Jul 1998 11:42:08 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: ? about binmode() behavior
Message-Id: <6php2g$6e1$1@pegasus.csx.cam.ac.uk>

Brent Verner <REPLY_TO_damonbrent@earthlink.net> wrote:
>>>     print <SOMEFILE> "$buffer";
>
>how do i fix the print statement not to use the line operator, i'm not sure
>what you mean by that?

  SOMEFILE  is a filehandle

  <SOMEFILE> is the operator which reads one line from that filehandle.

I don't think you want to read a line at this point.


Mike Guy


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

Date: Mon, 27 Jul 1998 09:13:48 -0400
From: "Brent Verner" <REPLY_TO_damonbrent@earthlink.net>
Subject: Re: ? about binmode() behavior
Message-Id: <6phuar$afs$1@fir.prod.itd.earthlink.net>


M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote in message
6php2g$6e1$1@pegasus.csx.cam.ac.uk...

>>
>>how do i fix the print statement not to use the line operator, i'm not
sure
>>what you mean by that?
>
>  SOMEFILE  is a filehandle
>
>  <SOMEFILE> is the operator which reads one line from that filehandle.
>
>I don't think you want to read a line at this point.
>


right on, right on.  yeah, i woke up from a weeks worth of headache,
heartache, and general stupidity and realized that the <FILE> is a special
read by line syntax, ...hmm what basic things get lost when you 'think' you
know what you're doing...i slap my wrist.

thanks,

brent




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

Date: Mon, 27 Jul 1998 12:21:37 +0100
From: Mark Simonetti <se96ms@english.iielr.dmu.ac.uk>
Subject: Arrays n Patterms
Message-Id: <Pine.OSF.3.96.980727122020.30087A-100000@english.iielr.dmu.ac.uk>

Is there a nicer way to do this ?

$_ =~ /$patt/;
@$line = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);

Basically, I want all the results from the pattern match to go into the
"line" array.

Mark.
--
=================================
Mark Simonetti
se96ms@dmu.ac.uk
marks@webleicester.co.uk
http://www.cms.dmu.ac.uk/~se96ms/
=================================

"I used to be indecisive, but now I'm not so sure."



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

Date: Mon, 27 Jul 1998 12:24:38 GMT
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Arrays n Patterms
Message-Id: <MPG.10263434198ae7ec98968b@news.scescape.net>

In article <Pine.OSF.3.96.980727122020.30087A-
100000@english.iielr.dmu.ac.uk> on Mon, 27 Jul 1998 12:21:37 
+0100, Mark Simonetti (a) felt the following information to be of 
use:
> Is there a nicer way to do this ?
> 
> $_ =~ /$patt/;
> @$line = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);
> 
> Basically, I want all the results from the pattern match to go into the
> "line" array.
> 

Howabout:

@Line = $_ =~ /<pattern>/;

Or, if using $_ as in above:

@Line = /<pattern>/;

$Line[0] will equal $1, $Line[1] will equal $2 and so on.

Hope this helps!

--Matthew


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

Date: 27 Jul 1998 12:00:56 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Arrays n Patterms
Message-Id: <6phq5o$6v1$1@pegasus.csx.cam.ac.uk>

Mark Simonetti  <se96ms@english.iielr.dmu.ac.uk> wrote:
>Is there a nicer way to do this ?
>
>$_ =~ /$patt/;
>@$line = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);
>
>Basically, I want all the results from the pattern match to go into the
>"line" array.

 @$line = /$patt/;

>From perldoc perlop section on `m/PATTERN/cgimosx':

             If used in a context that requires a list value, a
             pattern match returns a list consisting of the
             subexpressions matched by the parentheses in the
             pattern, i.e., ($1, $2, $3...).


Mike Guy


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

Date: 27 Jul 1998 12:15:04 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Arrays n Patterms
Message-Id: <901542296.113965@thrush.omix.com>

[posted & mailed]

Mark Simonetti <se96ms@english.iielr.dmu.ac.uk> wrote:
: Is there a nicer way to do this ?
: $_ =~ /$patt/;
: @$line = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);

	@$line = (/$patt/);
-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Mon, 27 Jul 1998 14:38:48 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: Arrays n Patterms
Message-Id: <35BC82E8.C0B0504F@nortel.co.uk>

Mark Simonetti wrote:
> 
> Is there a nicer way to do this ?
> 
> $_ =~ /$patt/;
> @$line = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);

The following works, but doesn't convince me too much:

$_ = 'blab';
/(.)(.)(.)(.)/;
foreach $i(1..4) {
  push @arr, $$i;
}

print join('--',@arr);

Gives: b--l--a--b


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: 27 Jul 1998 13:51:36 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Arrays n Patterms
Message-Id: <6pi0l8$rmb$1@client3.news.psi.net>

Mark Simonetti (se96ms@english.iielr.dmu.ac.uk) wrote on MDCCXCI
September MCMXCIII in <URL: news:Pine.OSF.3.96.980727122020.30087A-100000@english.iielr.dmu.ac.uk>:
++ Is there a nicer way to do this ?
++ 
++ $_ =~ /$patt/;
++ @$line = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);

    $line = [/$patt/];

++ Basically, I want all the results from the pattern match to go into the
++ "line" array.

But $line is a ref to an anon array in your example. If you want to
put in a named array, use

    @line = /$patt/;



Abigail
-- 
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
           print+Just (), another (), Perl (), Hacker ();'


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

Date: 27 Jul 1998 08:28:33 -0400
From: ehrlich@cse.psu.edu (Daniel R Ehrlich)
Subject: Compiling Perl 5.00[45] under AIX 4.2.1.0
Message-Id: <6phrph$bj9$1@daneel.cse.psu.edu>


Hello all.  I was wondering if anyone has compiled Perl 5.00[45] under
AIX v4.2.1.0?  I tried using the AIX 4.1 hints, but things did not compile
cleanly.  Any suggestions or pointers to a hints file for AIX 4.2?

Thanks,
Dan Ehrlich

-- 
Dan Ehrlich - Systems Analyst - PSU Computer Science and Engineering
"Universities should be safe havens where ruthless examination of realities
 will not be distorted by the aim to please or inhibited by the risk of
 displeasure." - Kingman Brewster


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

Date: Mon, 27 Jul 1998 13:56:10 GMT
From: "Le NETtoyeur" <NETtoyeur@usa.net>
Subject: Re: Compiling Perl 5.00[45] under AIX 4.2.1.0
Message-Id: <01bdb966$e80cd600$0c4ec383@einstein>

Daniel R Ehrlich <ehrlich@cse.psu.edu> a icrit dans l'article
<6phrph$bj9$1@daneel.cse.psu.edu>...
> 
> Hello all.  I was wondering if anyone has compiled Perl 5.00[45] under
> AIX v4.2.1.0?  I tried using the AIX 4.1 hints, but things did not
compile
> cleanly.  Any suggestions or pointers to a hints file for AIX 4.2?
> 
> Thanks,
> Dan Ehrlich

Why bothering to compile the source? You can download the
pre-compiled version of Perl (and other freewares) for AIX 4.x at:

     http://www-frec.bull.com

Le /\/ETtoyeur
NETtoyeur@usa.net
"Windows est une fenjtre ouverte sur le monde fermi"



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

Date: 27 Jul 1998 15:46:10 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: getting  the binary represenation of a number
Message-Id: <oeeogubo419.fsf@alpha.hut.fi>


xxxx@xxxx.xxx (Amy Rogers) writes:

> 
> Hi-
> 
> I'm a perl newbie. I'm trying to understand how to get the binary
> representation of a number. The process given in a book (David Till's
> Teach yourself Perl in 21 days) does not make it clear how it works and
> would like to hear another way to look at it, if at all possible.  

perl -le 'print join "", unpack("B*", pack("N", 1998))'

> On the same subject here's a short program that uses the << operator to
> print out the first 16 powers of 2. The answer is given below, but I'm
> having trouble understanding the "$value = $value << 1;" line. I
> understand that I should convert the $value to a bit notation so I could

No you don't need to. $value = $value << 1 is doing the needed shift.

> shift the first bit out to the right by one to get the new value. 
> 
> $value = 1;
> $counter = 0;
> while ($counter < 16 ) {
>    print "2 to the power $counter is $value\n";
>    $value = $value << 1; 
>    $counter++;
> 
> On the other hand, even if I had understood the whole bit notation
> conversion, I wonder what relevancy, if at all, it has for the beginner

Bit notation is needed if you handle bits (bit vectors, bit matrices)
or the raw binary representation of numbers...which admittedly aren't
first on the beginner menu.

> like myself?  The "Learning Perl, 2nd edition" doesn't appear touch on
> this subject at all. 
> 
> Amy
> aro@dnai.com

-- 
$jhi++; # http://www.iki.fi/~jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: Mon, 27 Jul 1998 09:11:05 -0400
From: "Brent Verner" <REPLY_TO_damonbrent@earthlink.net>
Subject: Re: having problems reading STDIN
Message-Id: <6phu5q$aa2$1@fir.prod.itd.earthlink.net>



>Try
>
> while ($rc = read(STDIN, $buffer, 4096)) {}


yup, that's what i found to use, more or less.
i have much to learn...

thanks,

brent



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

Date: Mon, 27 Jul 1998 15:44:21 +0300
From: tzahi uni <tzahi@tase.co.il>
Subject: How can I get the name of the current subroutine ?
Message-Id: <35BC7624.B7445391@tase.co.il>

hi ,
please help,
I need to know in which variable I can get the name of the current
subroutine.

thanks ,
tzahi



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

Date: Mon, 27 Jul 1998 13:14:26 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: If statement does not compare correctly
Message-Id: <35BC6F22.B25BDD3D@nortel.co.uk>

Leon, Schmetz wrote:
> 
> # I am trying to find out wether one or more bits are set in a given
> # value. Below is my testscript. Can you explain why Perl does
> # not find values equal????
> 
> if ((-1609432919 | -2147483648) == -1609432919)
> {
>    print "\n  Matched value";
> }
> else
> {
>    print "\n  If statement does not find this equal";
> }
This is the bitwise or operator:

print -1609432919 | -2147483648 gives:

2685534377

This is the bitwise and operator:

if ((-1609432919 & -2147483648) == -2147483648)
{
   print "\n  Matched value";
}
else
{
   print "\n  If statement does not find this equal also";
}

print -1609432919 & -2147483648 gives:

2147483648

This is the bitwise and operator:






-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Mon, 27 Jul 1998 13:20:46 GMT
From: creiner@my-dejanews.com
Subject: launching programs using CGI and Perl Win 32
Message-Id: <6phure$at6$1@nnrp1.dejanews.com>

Hi!

I'm a newbie and have a problem I can't find a solution for:

I'm trying to develope a Web-interface for our exchange server and use Perl 5
for Win32. I have to launch the administrator tool admin.exe comming with
exchange server with some comandline options to export some information. When
I use something like

  system('c:/exchsrvr/bin/admin.exe');

or my second version

use Win32::Process;
use Win32;
app = "c:/exchsrvr/bin/admin.exe";
$cmd = "admin.exe /e";
$dir = ".";
Win32::Process::Create($ProcessObj,$app,$cmd,0,DETACHED_PROCESS,$dir)  || die
print "ERROR";
$ProcessObj->SetPriorityClass(HIGH_PRIORITY_CLASS) || die print "ERROR";
$ProcessObj->Wait(INFINITE) || die print "ERROR";

It starts a process on the server (which seems to do nothing) and the client
freezes. Has anybody a solution for my problem?

Thanks in advance,

  * Christian *




-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Mon, 27 Jul 1998 14:47:29 +0200
From: Bernd Zimmermann <berni@ping-net.de>
Subject: perl and setuid via WEB (apache)
Message-Id: <35BC76E1.1252D58F@ping-net.de>

Hi !

I have perl 5.004_04, Apache 1_3_0 and want to execute a script
with suid root..

Problem : chown root and chmod u+s did not work, because the
script is called via the apache and still have the uid from the apache.

I  cannot user apaches suexec, because i want to run the script as root.

So whats the trick ?

Thankx a lot for help

Bernd




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

Date: 27 Jul 1998 13:53:03 GMT
From: Dan Nguyen <nguyend7@egr.msu.edu>
Subject: Re: PLEASE HELP: Simple ascii to binary script
Message-Id: <6pi0nv$l64$1@msunews.cl.msu.edu>

James <James@comp4ncr.com> wrote:
: I am an inexperienced programmer trying to learn Perl. Just for fun, I
: am trying to write a program that will convert ascii to binary.

Are you inexperience at posting to newsgroups as well.  As Uri pointed
out, PLEASE do not post binaries.  I know I prefer to read the code
with the message.

I'll be nice and show you the code that will do what I think you sort
of want.


#!/usr/local/bin/perl

while (<>) {
     my @ascii = map { chr $_ } unpack "C*", $_;
     map { print "$_:\t", (unpack "B8", $_), "\n"; } @ascii;
}


I'll leave it to you to figure out what it does.

-dan

-- 
           Dan Nguyen            | There is only one happiness in
        nguyend7@msu.edu         |   life, to love and be loved.
http://www.cse.msu.edu/~nguyend7 |                   -George Sand



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

Date: 27 Jul 1998 11:31:44 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Problem with random numbers
Message-Id: <6phof0$682$1@pegasus.csx.cam.ac.uk>

ch <wodehouse@cheerful.com> wrote:
>I have a script to choose a random song from over 15,000. The problem is
>that the choice made by the script is not random enough (some songs get
>chosen too much, others not at all); initialization of the script is done by
>Srand(timer), then a random number is chosen and multiplied by 15,000...  is
>there any better way of choosing a random number, something that is _really_
>random?

If you're running perl5.004 or later, you don't need to call srand() at
all.    Indeed, you're better off if you don't.    Perl will choose a
seed more random than anything you can dream up (by grabbing various
internal system things).    See perldoc -f srand.

(And if you're running an earlier Perl, upgrade.)

You should also be aware that Perl simply uses the random number
generator provided by the underlying C library.    On many platforms
this provides as few as 15 bits.     To see what youre platform does,
try
         perl -MConfig -e 'print "$Config{randbits}\n"'

Having as few as 15 bits can lead to problems with non-uniform rounding.

Using your algorithm above, the random number generator will
produce  N/32768, for some integer N in [0, 32767] and you will choose
the value  int(15000*N/32768).    For the first few values of N, these
values are

0 0 0 1 1 2 2 3 3 4 4 5 5 5 6 6 7 7 8 8
9 9 10 10 10 11 11 12 12 13 13 14 14 15 15 16 16 16 17 17
18 18 19 19 20 20 21 21 21 22 22 23 23 24 24 25 25 26 26 27
27 27 28 28 29 29 30 30 31 31 32 32 32 33 33 34 34 35 35 36
36 37 37 37 38 38 39 39 40 40 41 41 42 42 43 43 43 44 44 45
45 46 46 47 47 48 48 48 49 49 50 50 51 51 52 52 53 53 54 54
54 55 55 56 56 57 57 58 58 59 59 59 60 60 61 61 62 62 63 63
64 64 65 65 65 66 66 67 67 68 68 69 69 70 70 70 71 71 72 72
73 73 74 74 75 75 75 76 76 77 77 78 78 79 79 80 80 81 81 81
82 82 83 83 84 84 85 85 86 86 86 87 87 88 88 89 89 90 90 91
91 ...

You notice that some values (0, 5, 10, 16, 21 ... ) get three bites of
the cherry while the rest get only two.    So these preferred values
will turn up 50% more often than the rest.

To avoid this problem, always use an argument for rand() which is a
power of two, and throw away any values which are out of range, i.e.

       my $r;
       1 while ($r = rand(16384)) > 15000;

I don't know whether this is the complete explanation for your
"not random enough".    It certainly doesn't explain "others not at all",
unless that is just the normal operation of the statistics.


Mike Guy


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

Date: 27 Jul 1998 12:37:50 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Problem with random numbers
Message-Id: <6phsau$8bg@news-central.tiac.net>

In article <6pd93p$ff4$1@dinkel.civ.utwente.nl>,
ch <wodehouse@cheerful.com> wrote:

>I have a script to choose a random song from over 15,000. The problem is
>that the choice made by the script is not random enough (some songs get
>chosen too much, others not at all); initialization of the script is done by
>Srand(timer), then a random number is chosen and multiplied by 15,000...  is
>there any better way of choosing a random number, something that is _really_
>random?

What is your host?  On a linux system there is a device from which you can
read random data (/dev/random and /dev/urandom, the difference is
explained in /usr/src/linux/drivers/char/random.c if you have source on
line.  urandom is probably better to use on a web application as it won't
wait for the entropy pool)  Some code to do this might be:

#!/usr/local/bin/perl -w

$randomDev = '/dev/urandom';
$randomLimit = 15_000;
$intSize = length pack 'I';

open RAND, "<$randomDev" or die "$0: can't open $randomDev ($!)\n";

for (1 .. 10) {
  unless (sysread (RAND, $buffer, $intSize) == $intSize) {
    die "$0: couldn't read $intSize bytes from $randomDev\n";
  }
  $number = unpack ('I', $buffer) % $randomLimit;

  print "$_: $number\n";
}

close RAND;

__END__

The perl documentation for srand in recent distributions describes how to
seed perl's random number generator to avoid common traps.  In fact with
recent perls srand is automatically called for you, the perldoc -f on my
perl - 5.005 - says this for rand and srand:

       rand EXPR

       rand    Returns a random fractional number greater than or
               equal to 0 and less than the value of EXPR.  (EXPR
               should be positive.)  If EXPR is omitted, the
               value 1 is used.  Automatically calls srand()
               unless srand() has already been called.  See also
               srand().

               (Note: If your rand function consistently returns
               numbers that are too large or too small, then your
               version of Perl was probably compiled with the
               wrong number of RANDBITS.)

[...]

       srand EXPR

       srand   Sets the random number seed for the rand()
               operator.  If EXPR is omitted, uses a semi-random
               value based on the current time and process ID,
               among other things.  In versions of Perl prior to
               5.004 the default seed was just the current
               time().  This isn't a particularly good seed, so
               many old programs supply their own seed value
               (often time ^ $$ or time ^ ($$ + ($$ << 15))), but
               that isn't necessary any more.

               In fact, it's usually not necessary to call
               srand() at all, because if it is not called
               explicitly, it is called implicitly at the first
               use of the rand() operator.  However, this was not
               the case in version of Perl before 5.004, so if
               your script will run under older Perl versions, it
               should call srand().

               Note that you need something much more random than
               the default seed for cryptographic purposes.
               Checksumming the compressed output of one or more
               rapidly changing operating system status programs
               is the usual method.  For example:

                   srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);

               If you're particularly concerned with this, see
               the Math::TrulyRandom module in CPAN.

               Do not call srand() multiple times in your program
               unless you know exactly what you're doing and why
               you're doing it.  The point of the function is to
               "seed" the rand() function so that rand() can
               produce a different sequence each time you run
               your program.  Just do it once at the top of your
               program, or you won't get random numbers out of
               rand()!

               Frequently called programs (like CGI scripts) that
               simply use

                   time ^ $$

               for a seed can fall prey to the mathematical
               property that

                   a^b == (a+1)^(b+1)

               one-third of the time.  So don't do that.

Please check the version of perl you're using to see whether srand gets
automatically called (perldoc -f srand should tell you.)

Recent perl distributions contain the list of frequently asked questions
(FAQs) and 

  perldoc perltoc

(table of contents) indicates that section 4 contains the question "Why
aren't my random numbers random?" and an anaser to it.  To see section 4
you can use the command

  perldoc perlfaq4

or of you don't have the perlfaq docs installed a visit to
http://www.perl.com will let you follow the FAQs link.

Usually using the built generator, properly seeded, in is probably the
easiest thing to do.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 27 Jul 1998 11:06:18 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Reacting to 1 of 10 or so possible values.... Need some streamlining help.
Message-Id: <6phmva$5jn$1@pegasus.csx.cam.ac.uk>

Jaime Metcher  <metcher@spider.herston.uq.edu.au> wrote:
>Genuine, non-sarcastic question: I can see that this is more perlish,
>but why is it more streamlined?  For only ten possibilities, if all
>equally likely, the original version is doing an average of five tests
>per run.  Is it really better to build a dispatch (despatch?) table for
>this?

Well, I didn't claim it was more streamlined.   It does reduce the depth
of nesting of conditionals, which many people like.   It also makes life
easier if the actions for some requests are the same, or similar, so
the subroutines can be combined.    Or it could be that the
"set up environment" and "action" parts could be separated, allowing
more common cases.


Mike Guy


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

Date: Mon, 27 Jul 1998 12:27:03 GMT
From: root.noharvest.\@not_even\here.com (-)
Subject: Re: Recent Secret Government Experiments Killing People!!!
Message-Id: <35bc71fc.107583418@news2.cais.com>

Nobody <somewhere@over.the.rainbow> Said this:

>Ah... some enlightenment finally.  I see.  I don't suppose we could get more
>information on this person and send them off to Charter.  Too bad.  All this
>technology and yet we still have crazy people about.
>

I suspect Tove is right, this person was most likely just trolling for
email addresses.


>Slithey Tove wrote:
>
>>
>>
>>
>>      No, because this person is a schizophrenic. Either that, or a troll who
>> has worked with schizophrenics and knows how they think. His penultimate
>> paragraph is a textbook example of a common schizophrenic delusion, 'thought
>> insertion' and 'thought deletion' by radio control.
>>
>>      There's no point in arguing with him or trying to convince him of the
>> absurdity of his views. You're not arguing with a person capable of reason,
>> but with a faulty dopaminergic synapse. (Or with a troll impersonating a
>> person with faulty dopaminergic synapses, which is just as pointless.)
>>
>>      These folks do show up on Usenet occasionally. Schizophrenia is common.
>> One percent of every population that has been studied suffers from it. It is
>> a tragic and disabling disease. This fellow deserves our sympathy, but
>> there's no point in arguing with him or getting angry with him.
>>
>> -- Tove
>>
>



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

Date: Mon, 27 Jul 1998 13:44:36 -0700
From: Dave <davidmcg@cqm.co.uk>
Subject: Re: Recent Secret Government Experiments Killing People!!!
Message-Id: <35BCE6B4.4A99@cqm.co.uk>

Hmmm..

That's not all..

How many ppl in the group are willing to believe the fact that the AIDS
virus was NOT ACCIDENTAL.  After reading a txt file recently of a
supposed interview that took place in America, it was revealed that the
AIDS virus could either be the result of chemical warfare research gone
wrong or a attempt at population control by the US Government.

Personally, I'm more willing to believe the latter.  Both government's
are all back-stabbing bastards and nobody will ever change my opinion on
that.

Makes you think though, does'nt it.  How many more secrets has the
government kept from us over the years.  Why are they so afraid of ppl
like ourselves, are they afraid we might uncover something we should'nt.

I think we all might have the idea that all this shit about secret bases
in Nevada could be rumoured by the government themselves to cover up
something a bit more sinister.

I am now going to shutup before this posting begins to sound like some
bad episode of the X-Files...

Dave

PS : I'm moving to London soon all the way from Paisley, Scotland, what
the scene like down there and what about the 2600 Meets at the
Trocadero?


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

Date: 27 Jul 1998 10:46:44 GMT
From: lobo@pinon.ccu.uniovi.es (Ivan Fernandez Lobo)
Subject: Re: Simple (I hope) Apache/NT/Perl question
Message-Id: <6phlqk$365$1@sci.cpd.uniovi.es>

> The answer, in the context of this group, was clear enough: the question
> clearly had nothing to do with the perl language, and therefore was
> clearly off-topic.  There are excellent reasons for having usenet rules,
> and you are a living demonstration of why the moderated perl group was
> needed.

> You don't want to read, do you?  A good answer has already been
> supplied: so go and post the appropriate details of your problem to an
> appropriate group, where help is no doubt already available. 

> Heaven knows how you think you can tell that it's "the same problem".
> The only "same problem" that I can see here is an inability to choose an
> appropriate group for posting.


Ok Mr. Moderated !! But I still think the question isn't off-topic. How do you
explain people looking for the solution to this problem start searching in this
Newsgroup ?  Well, have fun keeping the integrity of this Newsgroup. Next time
I'll try to find a group where the penalty for making a mistake is not so
hard. 

       Ivan F. Lobo


P.S. By the way do those usenet rules say something about allowed mistakes ?




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

Date: 27 Jul 1998 11:37:41 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: struggling with date
Message-Id: <6phoq5$6c3$1@pegasus.csx.cam.ac.uk>

In article <35BB81DF.42C63006@shaw.wave.ca>,
Rick Delaney  <rick.delaney@shaw.wave.ca> wrote:
>Boson wrote:
>> I am looking for a way to get a date depending of the current weekday.
>> Here is my pseudo-code:
>> 
>> if weekday = sunday then date = today's date
>> else date = last sunday's date
>> 
>> I have been trying to use localtime but I cannot find the solution. I
>> know I cannot just substract the number of days between current
>> weekday and last sunday - that would be wrong when last sunday
>> occurred last month.
>> 
>
>print most_recent_sunday(time);
>sub most_recent_sunday {
>    my $time = $_[0];
>    my @T    = localtime($time);
>    $T[6] ? localtime($time - 86400 * $T[6]) : @T;# assume list context 
>}

As mentioned in another current thread, that doesn't work if you're
near to a daylight saving change.


Mike Guy


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

Date: Mon, 27 Jul 1998 10:18:31 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: struggling with date
Message-Id: <Ewr0Mv.GJv@csc.liv.ac.uk>

In article <35bb6522.10427739@news.earthlink.net>,
boson@earthlink.net (Boson) writes:
> Hi,
> 
> I am looking for a way to get a date depending of the current weekday.
> Here is my pseudo-code:
> 
> if weekday = sunday then date = today's date
> else date = last sunday's date
> 
> I have been trying to use localtime but I cannot find the solution. I
> know I cannot just substract the number of days between current
> weekday and last sunday - that would be wrong when last sunday
> occurred last month.
> 

Something like this might work.

#!/usr/local/bin/perl5 -w

use strict; 

my ($n,$m,$y,$w);

(undef,undef,undef,$n,$m,$y,$w,undef) = localtime;

my $date = $w ? last_sun($n,$m,$y,$w) : $n."/".($m++)."/".$y;

print "$date\n";

1;

sub last_sun {
   my ($n,$m,$y,$w) = @_;
   my @d_in_m = qw(31 28 31 30 31 30 31 31 30 31 30 31); 

   my $new_dt = $n - $w;
   if ($new_dt <= 0) { 
      $m = $m > 0 ? $m-- : 12;
      $new_dt += $d_in_m[$m];
   }

   my $date = $n."/".(++$m)."/".$y;

   return $date;
}

Dealing with leap years and leap centuries is left as an exercise
for the reader. Also this will print 27/7/100 in the year 2000
so you will need to modify for that as well.

HTH.
--
Ian J. Garlick
ijg@csc.liv.ac.uk

Any sufficiently advanced technology is indistinguishable from a rigged
demo.


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

Date: Mon, 27 Jul 1998 10:24:14 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: struggling with date
Message-Id: <Ewr0wE.Gw6@csc.liv.ac.uk>

In article <Ewr0Mv.GJv@csc.liv.ac.uk>,
ijg@csc.liv.ac.uk (I.J. Garlick) writes:
> #!/usr/local/bin/perl5 -w
> 
> use strict; 
> 
> my ($n,$m,$y,$w);
> 
> (undef,undef,undef,$n,$m,$y,$w,undef) = localtime;
> 
> my $date = $w ? last_sun($n,$m,$y,$w) : $n."/".($m++)."/".$y;
> 
> print "$date\n";
> 
> 1;
> 
> sub last_sun {
>    my ($n,$m,$y,$w) = @_;
>    my @d_in_m = qw(31 28 31 30 31 30 31 31 30 31 30 31); 
> 
>    my $new_dt = $n - $w;
>    if ($new_dt <= 0) { 
>       $m = $m > 0 ? $m-- : 12;
>       $new_dt += $d_in_m[$m];
>    }
> 
>    my $date = $n."/".(++$m)."/".$y;
                ^^
whoops got this wrong, should read

     my $date = $new_dt."/".(++$m)."/".$y;
> 
>    return $date;
> }
> 
> Dealing with leap years and leap centuries is left as an exercise
> for the reader. Also this will print 27/7/100 in the year 2000
> so you will need to modify for that as well.
> 
> HTH.

--
Ian J. Garlick
ijg@csc.liv.ac.uk

Any sufficiently advanced technology is indistinguishable from a rigged
demo.


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

Date: 27 Jul 1998 09:16:23 EDT
From: "Sam Irion" <persoft@concentric.net>
Subject: Submit only Once
Message-Id: <6phuj7$qo3@examiner.concentric.net>

Can anyone give me any advice or direction on how to prevent the user from
using the browser's back button to go back to a form and repost it?

I have a perl script that send out a couple of emails after a large form is
posted.  The form has a lot of required fields.  My thoughts are that if I
can prevent the user from backing up and posting the same data again (by
offering a new reset form), those that are inclined to back up and submit
dozens of times won't feel like it is worth the effort.

Any advice will be appreciated!

Thanks,

-Sam-

sam@bricktown.net





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

Date: Mon, 27 Jul 1998 12:35:20 GMT
From: root.noharvest.\@not_even\here.com (-)
Subject: Re: Unable to get REMOTE_HOST
Message-Id: <35bc7239.107644534@news2.cais.com>

"Thomas =?iso-8859-1?Q?=D8derud?=" <tho@sn.no> Said this:

>My ISP is running an Apache Server.
>
>In one of my script I retrive the REMOTE_HOST Environment Variable with
>the
>output being the ip adress. Does anybody know how to fix this..??
>

They are either running a newer version of Apache (1.3bxx or 1.3.0) or
have intentionally disabled hostname lookups.  

hostname lookups is an unnecessary waste of time, especially when the
server is just going to send a .html file.  

Rather than ask the ISP to enable hostname lookups, just add this to
your perl scripts to get the host names:

use Socket;

$hostname = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}),AF_INET);	


$hostname *should* now hold the host name, if DNS resolution
succeeded.  If not, it'll just have the IP address - but that's what
you'd get with hostname lookups anyway.




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

Date: 27 Jul 1998 15:00:05 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: Y2K problem in PERL with localtime()
Message-Id: <isbtqbe9ey.fsf@godzilla.kiere.ericsson.se>

EOZSARUH@nsf.gov (Erdem Ozsaruhan) writes:

> Any ideas?

1) Read the documentation
2) Read the FAQ
3) Think
-- 
                    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

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


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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