[18794] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 962 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 22 21:05:37 2001

Date: Tue, 22 May 2001 18:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990579914-v10-i962@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 22 May 2001     Volume: 10 Number: 962

Today's topics:
    Re:  Help: Can't use correctly File:Find in perl (Eric Bohlman)
    Re: Autosplit -a flag and trailing null fields (Charles DeRykus)
    Re: Building a source for Perl contracts <comdog@panix.com>
    Re: converting characters in email <troyr@vicnet.net.au>
    Re: delete() from array <bart.lateur@skynet.be>
        embeded perl - perl_parse crashes Java 1.2.2 and Java 1 (Kong Li)
    Re: Good source for Perl contracts ? (Eric Bohlman)
    Re: Handling JPEGs without modules (Eric Bohlman)
    Re: How can I convert a date (MM/DD/YYYY) to UTC time? <william.c.nelson@gte.net>
    Re: How can I convert a date (MM/DD/YYYY) to UTC time? (John Joseph Trammell)
    Re: How can I convert a date (MM/DD/YYYY) to UTC time? <jurgenex@hotmail.com>
    Re: How can I convert a date (MM/DD/YYYY) to UTC time? <bart.lateur@skynet.be>
    Re: How to localize error messages for testing? <krahnj@acm.org>
    Re: How to localize error messages for testing? <newspost@coppit.org>
    Re: is /$foo/ really bad?  <jeffp@crusoe.net>
    Re: module for combinatorics? (partitions etc) <ilya@math.ohio-state.edu>
    Re: module for combinatorics? (partitions etc) (Dave Bailey)
    Re: module for combinatorics? (partitions etc) <wellhaven@worldnet.att.net>
    Re: module for combinatorics? (partitions etc) <wellhaven@worldnet.att.net>
    Re: non repeating random numbers <goldbb2@earthlink.net>
    Re: oh c'mon please, one of you perl/unix gurus!!! <buggs@geekmail.de>
        Permuting days of the week (James Weisberg)
    Re: Permuting days of the week (Randal L. Schwartz)
    Re: Permuting days of the week (Abigail)
    Re: Permuting days of the week <todd@designsouth.net>
        setting priority from perl on linux <dball@bnb-lp.com>
    Re: setting priority from perl on linux <tony_curtis32@yahoo.com>
        Sorting data file on numerical field (Graham Cox)
    Re: Sorting data file on numerical field <tony_curtis32@yahoo.com>
        This String Formation does not work properly, pleaze he (Lars)
    Re: This String Formation does not work properly, pleaz <todd@designsouth.net>
    Re: url parsing (Craig Berry)
        Warning/Danger -- Don't use Perl for CGI (Mike Moosler)
    Re: Warning/Danger -- Don't use Perl for CGI <todd@designsouth.net>
    Re: Warning/Danger -- Don't use Perl for CGI <bart.lateur@skynet.be>
    Re: Warning/Danger -- Don't use Perl for CGI (Randal L. Schwartz)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 May 2001 22:36:03 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re:  Help: Can't use correctly File:Find in perl
Message-Id: <9eepkj$f72$5@bob.news.rcn.net>

64.158.66.163 wrote:

> If I'm understanding what you're asking for, then using a combination of opendir() and readdir() should do this quite nicely.

> So, if the directory was /home/me and you wanted all the directories contained directly beneath it, you could do:

> opendir(D, "/home/me") or die("Couldn't open /home/me for reading\n");
> my @entries = readdir(D);

> foreach (@entries) {
>   if (-d $_) {

Please don't post code that contains one of the most commonly 
warned-against mistakes ever.  Your are sentenced to write 100 times on 
the blackboard "readdir() returns only base names, not full path names.  
File-test operators want full path names."

>     # code here to record the directories
>   }
> }

> closedir(D);

> In this case, File::Find seems like overkill.

Overkill that works correctly is better than simplifications that don't.



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

Date: Wed, 23 May 2001 00:20:45 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Autosplit -a flag and trailing null fields
Message-Id: <GDrIAL.FsC@news.boeing.com>

In article <3B097380.46A5C9C4@mail.northgrum.com>,
John L. Allen <allenjo5@mail.northgrum.com> wrote:
>I find it annoying that the -a flag ignores trailing null fields.
>It does this because it uses  split()  with no limit parameter.
>As such, the -a flag is less awk-like than it could be.  If this
>was deliberate, perhaps there should be a -A flag (or whatever)
>to make autosplit use a -1 for the limit.
>

Good idea.  Possible workaround on a Unix command line:

perl -F'(\s+|$)' -lane \
'for(0..$#F){print $F[$_] if $F[$_]=~/\S/ or $_==$#F}' yourfile 

--
Charles DeRykus


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

Date: Tue, 22 May 2001 18:25:27 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Building a source for Perl contracts
Message-Id: <comdog-A6C372.18252722052001@news.panix.com>

In article <OLyO6.56876$I5.12393361@news1.rdc1.tn.home.com>, "Todd 
Smith" <todd@designsouth.net> wrote:

> This was my idea, but I'm sure people have had it before, and if I started
> the project at sourceforge, we could all help develop the site, so this
> wouldn't bring anybody any money unless you actually get a job to work on.

in the years that i've been working with Perl Mongers, this idea has
been proposed many times and there have been many starts by several
people.  the first mistake they all made was developing code for it.

and no one but Uri has actually gotten anything done on it though. ;)

people who come to usenet looking for answers aren't a good target
for consulting dollars, so if that is your motivation then you 
should re-evaluate the benefits.  on the other hand, you have to
be able to let potential employers know you have a service if you
want to make it of any use.  that's the tough part.  the technology
is not difficult at all - it's the mind share.

jobs.perl.org has been working for awhile, but it has no chance of
beating someone who has advertising dollars.

if you are still really excited about this, forget about the 
technology portion for a bit and think about the service portion.
figure out the market you want to serve.  if your answer has 
anything to do with writing code or web pages then you haven't 
answered the question.

once you have identified the market, analyze their needs.  again,
if you are thinking about web pages and code at this point, you
aren't do it right.

once you know what the market needs, figure out how to meet those
needs.  you can be a bit more specific here, but if you immediately
run to sourceforge you haven't thought about it enough. who else
services this market?  can you compete?  does the addition of
another hiring channel over-satuarate the market?  is it worth
your time to create something that lives in the shadow of monster.com
and the like? is it worth your time to create something that
potentially nobody will use (which is a real risk)?

if you get this far, and, considering the risks, still think its 
a good idea, you might want to invest some of your time.

having worked with several people who have tried to do this in
the past, including a couple of headhunters, i think the risk is
not worth the potential benefit.  you'll spend a lot of time
working on something that has a very high probability of either
languishing or being abandoned because there are already things out
there that do the job.

-- 
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: Wed, 23 May 2001 09:51:48 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: Re: converting characters in email
Message-Id: <nZCO6.2567$Ld4.116893@ozemail.com.au>

> Hi there,
>             I have a form in html which passes the value of a textarea to
a
> perl script which emails out the value.
>
> All works fine. However...users of the script copy and paste text from
> Microsoft Word which has smart quotes in it. It displays fine on the
> web..but when the user receives an email the smart quotes get converted to
>
> &#8220;&#8221;
>
> Is there some sort of encoding i can use or a work around that anyone
knows
> of?

More to the point..is there some sort of search replace i can use to get rid
of the smart quotes
ie s/&#8220;/\'/g

that won't work but..something similiar?

Thanks in advance






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

Date: Tue, 22 May 2001 23:33:14 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: delete() from array
Message-Id: <9otlgtskurtc6uei2e7e30hr62ssssea57@4ax.com>

Uri Guttman wrote:

>  BL> But you can't really use it.
>
>  BL> 	@remain = grep { exists $_ } @ary;
>
>  BL> doesn't even compile.
>
>well, exists needs to be given a real location and not a value. 

Well... in the grep block, $_ is an *alias* to the array element, not
just its value.

Perhaps I've had a bit too much of the recent discussions on the Perl6
mailing lists, so I kind of expected exists() to test a "property" of
the array element. That property would also be accessible through the
alias, I guess.

-- 
	Bart.


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

Date: 22 May 2001 17:48:32 -0700
From: likong@us.sina.com (Kong Li)
Subject: embeded perl - perl_parse crashes Java 1.2.2 and Java 1.3.0, but not Java 1.1.8
Message-Id: <bd472bc6.0105221648.6e51c91a@posting.google.com>

Hi,

I was trying to call embedded perl (5.6.1) in Java (1.3.0 and 1.2.2)
via JNI interface.  The perl_parse() function keeps crashing/core
dump.  But the same code works fine with Java 1.1.8.  A simiple
printf("Hello world\n") works fine in all Java versions.

Environment:
Solaris 2.8 (with the patches required/recommended by Sun)
Perl 5.6.1
Java 1.3.0_02

With Java 1.3.0_02, the following is the error message:
# # An unexpected exception has been detected in native code outside
the VM.# Program counter=0xeb226808
#
# Problematic Thread: prio=5 tid=0x28000 nid=0x1 runnable 
#
Abort

The "truss" program indicates the crash was due to fault #6
(FLTBOUNDS, MEMORY BOUNDS (invalid address)) and signal #11.

I have tried various ways to re-compile perl with Sun's cc or gcc,
with or without "usethreads", "useithreads", use perl5's memmory
allocation or not, use perl's perlmain.c or miniperlmain.c, etc.
without luck.

I also tried JPerl; it does not work with Java 1.3 either but it does
work with Java 1.1.  JPL is not what I want therefore I did not try it
(The doc of JPL also indicates it works with Java 1.1.)

I heard there are some changes in JNI between Java 1.1 and 1.2.  May
be it is because of these changes?  If so, what are they?  How to fix
it?

Any hints or recommendations?  Please email to likong@us.sina.com
directly.  I will summarize if there is sufficient interest.

Thanks.

Kong
likong@us.sina.com


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

Date: 22 May 2001 22:53:11 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Good source for Perl contracts ?
Message-Id: <9eeqkn$f72$6@bob.news.rcn.net>

Snakedjip <snakedjip@nospamyahoo.com> wrote:
> I am looking for a good source (web site, head-hunter...) to help me find
> contract work for the web with Perl/mod-Perl.  This would have to be
> tele-commute work, as I have no intention whatsoever of moving and/or
> commuting...  And since I'm in Canada, canadian programmers (cheap cheap
> cheap) would have to be allowed...

Try <URL:http://jobs.perl.org>, which is run by the Perl Mongers.



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

Date: 22 May 2001 22:23:25 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Handling JPEGs without modules
Message-Id: <9eeost$f72$4@bob.news.rcn.net>

peter pilsl <pilsl_@goldfisch.at> wrote:
> however: why not ftp the module-files to your host after proper compiling 
> them on your own machine and then include them using a command like 
> use lib "whatpathever"

That will only work if your machine has the exact same architecture and OS 
as the Web host's machine, and even then only if you have the same 
compiler that the host's machine's perl was compiled with.  "Solutions" 
that depend on lots of coincidences tend not to work very well.



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

Date: Tue, 22 May 2001 22:15:51 GMT
From: Bill Nelson <william.c.nelson@gte.net>
Subject: Re: How can I convert a date (MM/DD/YYYY) to UTC time?
Message-Id: <3B0AE000.6103344@gte.net>

This is a multi-part message in MIME format.
--------------10D126B453E3CF3CEEE64205
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

No, that goes from UTC to human readable time.  I.E.  I can go from UTC,
"954991003", and make it "Tue Mar 27 14:01:42 2001" by running the UTC
through the following code:

$utcTime = 954991003;
$humanReadable = gmtime($utcTime);

That produces a value of "Tue Mar 27 14:01:42 2001" for the $humanReadable
variable.

I want to go the other way around.  I want to take something like
11/10/2000 and turn it into a UTC time so that I can do an easy comparrison
of two timestamps in UTC.

thanks,

bill


Todd Smith wrote:

> man perlfunc / gmtime
>
> gmtime EXPR
>                Converts a time as returned by the time function to a
>                9-element array with the time localized for the standard
>                Greenwich time zone.  Typically used as follows:
>
> is that it?

--------------10D126B453E3CF3CEEE64205
Content-Type: text/x-vcard; charset=us-ascii;
 name="william.c.nelson.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Bill Nelson
Content-Disposition: attachment;
 filename="william.c.nelson.vcf"

begin:vcard 
n:Nelson;Bill
tel;pager:727.468.6779
tel;cell:727.365.5677
tel;fax:727.579.1107
tel;work:727.576.0549 x213
x-mozilla-html:FALSE
url:http://www.bnelson.com
adr:;;;;;;
version:2.1
email;internet:isstb@flanet.com
title:Consultant/Trainer/Developer
fn:Nelson, Bill
end:vcard

--------------10D126B453E3CF3CEEE64205--



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

Date: Tue, 22 May 2001 22:21:02 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: How can I convert a date (MM/DD/YYYY) to UTC time?
Message-Id: <slrn9gln4v.8pf.trammell@bayazid.hypersloth.net>

On Tue, 22 May 2001 21:51:01 GMT, Bill Nelson wrote:
> Yes, but none that I can tell to take a date and convert it to
> UTC, only to go from UTC.

I think you're confusing UTC and Epoch.

-- 
According to the Genesis account, the tower of Babel was man's second
major engineering undertaking, after Noah's ark.  Babel was the first
engineering fiasco.
                                - F. Brooks, _The Mythical Man-Month_


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

Date: Tue, 22 May 2001 15:47:45 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How can I convert a date (MM/DD/YYYY) to UTC time?
Message-Id: <3b0aec91$1@news.microsoft.com>

"Bill Nelson" <william.c.nelson@gte.net> wrote in message
news:3B0AD4D0.6727AC4E@gte.net...
> I would like to do some date comparrisons via UTC time and am trying to
> determine how to converte a date format of something like:  12/01/2000
> to UTC without having to do all the math and figure out leap years and
> such.

I think you are somewhat confused. Your question doesn't make much sense.
- A date is something like e.g. 2001/05/22 (in whatever standard).
- A time is something like e.g. 18:34 o'clock, (and you are asking for the
timezone being in UTC).
They have pretty much nothing to do with each other and you simply cannot
convert a data into a time (be it UTC or any other time zone).

Maybe your date contains a time segment and you are trying to convert this
segment to UTC? Then you may want to look up locales and timezones.
Or are you asking for something totally different?

jue




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

Date: Tue, 22 May 2001 23:16:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How can I convert a date (MM/DD/YYYY) to UTC time?
Message-Id: <blslgt8eor2h5d54bas5q2b46krfo9chab@4ax.com>

Bill Nelson wrote:

>I would like to do some date comparrisons via UTC time and am trying to
>determine how to converte a date format of something like:  12/01/2000
>to UTC without having to do all the math and figure out leap years and
>such.

The standard module (as in: present on every perl installation)
Time::Local can turn combinations of year, month and day back into times
since the epoch.

Don't forget to subtract 1 from your month number (January = 0).

BTW is that December 1st of January 12th?

	use Time::Local;
	my $time = timegm(0, 0, 0, 1, 12-1, 2001);
	print scalar gmtime($time)
-->
	Sat Dec  1 00:00:00 2001

-- 
	Bart.


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

Date: Tue, 22 May 2001 22:16:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to localize error messages for testing?
Message-Id: <3B0AE53F.381AEB39@acm.org>

David Coppit wrote:
> 
> My grepmail script has a test script that tests both valid and invalid
> inputs. One of the invalid test cases tries to read from a file which
> does not exist, resulting in the usual "No such file or directory"
> message.
> 
> The problem is that in other languages, the message does not match,
> foiling the test script. Is there some easy way to localize my test
> script? For example, can I get access to the string table for error
> messages? Or do I have to probe the system to figure out what the
> message should be and update the test script on the fly?

$!      If used in a numeric context, yields the current
        value of errno, with all the usual caveats.  (This
        means that you shouldn't depend on the value of $!
        to be anything in particular unless you've gotten
        a specific error return indicating a system
        error.)  If used in a string context, yields the
        corresponding system error string.

Just use $! in a numeric context and you won't have to translate the
text messages.


John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 22 May 2001 18:45:55 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: How to localize error messages for testing?
Message-Id: <Pine.SUN.4.33.0105221843130.240-100000@mamba.cs.Virginia.EDU>

On Tue, 22 May 2001, John W. Krahn wrote:

> > One of the invalid test cases tries to read from a file which
> > does not exist, resulting in the usual "No such file or directory"
> > message.
> >
> > The problem is that in other languages, the message does not match,
> > foiling the test script.

> Just use $! in a numeric context and you won't have to translate the
> text messages.

No... I'm doing this:

  grepmail searchpattern nonexistentfile 1>output.log 2>error.log

I then compare the logs against the correct logs. The problem is that
the error message that gets displayed to the user by grepmail is not
always in english, so my diffs fail.

-- 
David



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

Date: Tue, 22 May 2001 18:50:54 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: is /$foo/ really bad? 
Message-Id: <Pine.GSO.4.21.0105221849300.17307-100000@crusoe.crusoe.net>

On May 22, Mark-Jason Dominus said:

>> I thought Perl recompiled a regex every time if there as a non-qr//d
>> variable found in it.
>> 
>> The -mre=debug results show otherwise...
>> 
>>   $rex = 'set\s+\w+\s+=\s+';
>> 
>>   @ARGV = '.cshrc';
>>   while (<>) { print if /$rex/ }
>
>When it compiled the regex, it saves the original uncompiled version.
>Next time through the loop, it checks to see if the uncompiled version
>(the string) is the same.  If it is, it doesn't bother to recompile it.
>
>So you do one extra string compare per loop iteration.

But... but... but...

Then how is that at all different from using a qr//'d variable?  Except,
of course, the:

  while (<>) { for $p (@qr_d_pats) { print if /$p/ } }

isn't as bad as if they WEREN'T qr//'d.  I see...

Well, that's not documented.  Perhaps I shall patch perlop.pod.

>It seems to me that followups should go to comp.lang.perl.misc.

Done.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




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

Date: 22 May 2001 22:33:28 GMT
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: module for combinatorics? (partitions etc)
Message-Id: <9eepfo$ot0$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
William Cardwell 
<EUSWMCL@am1.ericsson.se>], who wrote in article <3B0AC033.3AD90A85@am1.ericsson.se>:
> Thanks, I like it and the approach is intuitive. However, when you run
> it 100 times, aren't there too many ones? Suppose, I listed all
> combinations in a standard order, counted and and numbered them, then
> picked a random number bewteen 1 and the count, and picked that one, is
> it so likely it will contain one(s)?

If you suppose that you do not distinguish sums which differ only by
order, then you are asking whether part(n-1)/part(n) is close to 1;
here part(n) is the number of partitions of n.  Since part(n) grows
sub-exponentially, this is true indeed.

[I do not remember the original question, it may have fixed the number
of summand - but this does not influence the result.]

Why part(n-1)?  It coincides with the number of partitions of n which
have 1.  Thus part(n-1)/part(n) is the fraction of partitions of n
which have 1.

Ilya


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

Date: 23 May 2001 00:02:27 GMT
From: dave@sydney.daveb.net (Dave Bailey)
Subject: Re: module for combinatorics? (partitions etc)
Message-Id: <slrn9gllaa.k9e.dave@sydney.daveb.net>

On Tue, 22 May 2001 03:47:59 GMT, Mark Jason Dominus <mjd@plover.com> wrote:
>In article <3B098922.B5F32CA8@am1.ericsson.se>,
>William Cardwell  <EUSWMCL@am1.ericsson.se> wrote:
>>I'm thinking: A random pick would be a random pick from a list of all
>>possible combinations. I'm also thinking that this gets into a hugh
>>number quickly like the classical "Traveling Salesman Problem"
>
>This is irrelevant.  Consider the problem of shuffling an array of
>(1...$n).  The number of different permutations is exponential, and in
>fact is larger than the number of partitions that the original author
>was asking for.  Nevertheless, producing one at random is very easy.

I don't think this logic applies to the problem at hand.  Producing
a random permutation is easy because all that is needed to ensure 
randomness is the list of indices picked at each step.  It is a P
problem.  The problem posed in this thread is (I think) NP complete
and is probably reducible to the (NP complete) subset sum problem if 
we accept bounds on the range of integers which may be employed in 
constructing a solution.  Consider the simplified case:

Give a list of 4 integers in the range [1,3] which sum to 6.  Repetitions
are permissible, and all permutations of the list are considered 
identical:

There are two solutions, ignoring permutations:  (1,1,1,3) and (1,1,2,2).
The number 1 appears 5/8 of the time, 2 appears 1/4 of the time, and 3
appears 1/8 of the time.  Therefore, application of the logic of the 
permutation-picking algorithm to this problem would result in an uneven
distribution of answers.  In this case, I believe you would consistently
end up with (1,1,1,3) 14/27 of the time, and (1,1,2,2) 13/27 of the 
time.

--
Dave Bailey
davidb54@yahoo.com


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

Date: Wed, 23 May 2001 00:31:25 GMT
From: "Will Cardwell" <wellhaven@worldnet.att.net>
Subject: Re: module for combinatorics? (partitions etc)
Message-Id: <xxDO6.37730$4f7.2857436@bgtnsc06-news.ops.worldnet.att.net>


"Ilya Zakharevich" <ilya@math.ohio-state.edu> wrote in message
news:9eepfo$ot0$1@agate.berkeley.edu...
> [A complimentary Cc of this posting was sent to
> William Cardwell
> <EUSWMCL@am1.ericsson.se>], who wrote in article
<3B0AC033.3AD90A85@am1.ericsson.se>:
> > Thanks, I like it and the approach is intuitive. However, when you run
> > it 100 times, aren't there too many ones? Suppose, I listed all
> > combinations in a standard order, counted and and numbered them, then
> > picked a random number bewteen 1 and the count, and picked that one, is
> > it so likely it will contain one(s)?
>
> If you suppose that you do not distinguish sums which differ only by
> order, then you are asking whether part(n-1)/part(n) is close to 1;
> here part(n) is the number of partitions of n.  Since part(n) grows
> sub-exponentially, this is true indeed.
>
> [I do not remember the original question, it may have fixed the number
> of summand - but this does not influence the result.]
>
> Why part(n-1)?  It coincides with the number of partitions of n which
> have 1.  Thus part(n-1)/part(n) is the fraction of partitions of n
> which have 1.
>
>
I see now. I wasn't thinking how the tendency to the occurrence of 1 as an
addend increases as the number of addends approaches their sum. At extreme,
for example, if n=x the only partiton is 1,1,...1. Pretty elementary. Sorry
I was so dense.

Thanks to all, Will




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

Date: Wed, 23 May 2001 00:31:25 GMT
From: "Will Cardwell" <wellhaven@worldnet.att.net>
Subject: Re: module for combinatorics? (partitions etc)
Message-Id: <xxDO6.37731$4f7.2856993@bgtnsc06-news.ops.worldnet.att.net>


"Ilya Zakharevich" <ilya@math.ohio-state.edu> wrote in message
news:9eepfo$ot0$1@agate.berkeley.edu...
> [A complimentary Cc of this posting was sent to
> William Cardwell
> <EUSWMCL@am1.ericsson.se>], who wrote in article
<3B0AC033.3AD90A85@am1.ericsson.se>:
> > Thanks, I like it and the approach is intuitive. However, when you run
> > it 100 times, aren't there too many ones? Suppose, I listed all
> > combinations in a standard order, counted and and numbered them, then
> > picked a random number bewteen 1 and the count, and picked that one, is
> > it so likely it will contain one(s)?
>
> If you suppose that you do not distinguish sums which differ only by
> order, then you are asking whether part(n-1)/part(n) is close to 1;
> here part(n) is the number of partitions of n.  Since part(n) grows
> sub-exponentially, this is true indeed.
>
> [I do not remember the original question, it may have fixed the number
> of summand - but this does not influence the result.]
>
> Why part(n-1)?  It coincides with the number of partitions of n which
> have 1.  Thus part(n-1)/part(n) is the fraction of partitions of n
> which have 1.
>
>
I see now. I wasn't thinking how the tendency to the occurrence of 1 as an
addend increases as the number of addends approaches their sum. At extreme,
for example, if n=x the only partiton is 1,1,...1. Pretty elementary. Sorry
I was so dense.

Thanks to all, Will






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

Date: Tue, 22 May 2001 19:10:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: non repeating random numbers
Message-Id: <3B0AF1DA.C61E7C56@earthlink.net>

Benjamin Goldberg wrote:
> 
> David Chan wrote:
> >
> > On Thu, 8 Feb 2001, Jason from The Workshop wrote:
> >
> > > I have need to generate a random number between 1 and 50 without
> > > using a number that has already been generated.
[snip]
> If you want [to shuffle] the numbers 1..10000, you need an
> array with 10000 elements.  There *is* a way to eliminate this
> overhead!
> 
> Encrypt a counter with a small block cipher.

For those interested, I've thought of a slightly more efficient method
than what I'd had before.  It's the same concept (encrypt a counter and
decimate the output if necessary), but the size of the sboxes are
slightly smaller, and the amount of decimation needed is smaller. 
Before, the size of each sboxes was 2**ciel( log2(N)/2 ).  Here, I
reduce them to ciel(sqrt(N)).

use POSIX 'ceil';
sub mksbox {
	my $N = shift;
	my (@array,$i,$j)=(0..$N-1);
	for $i (0..$N-1) {
		$j = int rand $N;
		@array[$i,$j] = @array[$j,$i];
	}
}
sub shuffler {
	my $N = shift;
	my $M = ceil( sqrt( $N ) );
	my ($s0, $s1) = ([mksbox $M], [mksbox $M]);
	my ($s2, $s3) = ([mksbox $M], [mksbox $M]);
	my ($cl,$cr) = (0,0);
	return sub {
		my $res;
		do {
			return undef if $cr >= $M;
			my ($hi,$lo) = ($cl,$cr);
			$lo = $lo + $s0[$hi] % $M;
			$hi = $hi + $s1[$lo] % $M;
			$lo = $lo + $s2[$hi] % $M;
			$hi = $hi + $s3[$lo] % $M;
			$res = $hi*$M + $lo;
			if( ++$cl == $M ) { $cl = 0; ++$cr; }
		} until( $res < $N );
		return $res + 1;
	}
}

my $shuf = shuffler 10000;
while(defined $_ = &$shuf) {
	print $_, "\t";
}
print "\n";

For this version, each sbox has 100 elements, rather than 128.  So we've
gone from 512 array elements to 400.  A "normal" shuffle would have
10000 array elements.  As a result, we go from 1/19.5 of the memory of a
full shuffle down to using 1/25 of the memory.

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Wed, 23 May 2001 02:58:25 +0200
From: buggs <buggs@geekmail.de>
Subject: Re: oh c'mon please, one of you perl/unix gurus!!!
Message-Id: <9ef20d$kr7$02$1@news.t-online.com>

Hoi,
First rebuild / reconfigure the Apache won't help.
95% assured.

But chances are:
- the webserver runs in a more secure Enviroment ( jail / chroot()ed ... )
- your HomeDir is not accessable by the user which runs Apache

First check permission of your HomeDir ( perl5.6 dir etc.)
you would probably need 755 or rwxr-xr-x

If OK check if your HomeDir is accessible by a cgi:

print `ls /your/home/dir` .

If you can't it is a more secure ENV and you are fucked
without the admins.

Respect the way they run their webserver,
if you run perl5.6 tell them.

Buggs

P.S.
The Configfile for Apache is usually called "httpd.conf".


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

Date: Tue, 22 May 2001 18:17:23 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Permuting days of the week
Message-Id: <T2yO6.6074$DW1.277295@iad-read.news.verio.net>


   Here's a simple challenge.  
 
   Given the days of the week: Sun, Mon, Tue, Wed, Thu, Fri, Sat
I would like to take various permuations and sequences of those strings 
and fill the days in between. Examples: 

Sun-Sat = "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
Mon-Sun = "Mon,Tue,Wed,Thu,Fri,Sat,Sun"
Wed-Tue = "Wed,Thu,Fri,Sat,Sun,Mon,Tue"
etc, and sub-sequences:
Sun-Tue = "Sun,Mon,Tue"
Fri-Sun = "Fri,Sat,Sun"
etc.

   So a function like fill($from, $to) would fill up to seven days 
$from - $to and $from != $to so Mon-Mon, for example, is invalid.

Is there a clever solution for this?



-- 
World's Greatest Living Poster


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

Date: 22 May 2001 16:58:23 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Permuting days of the week
Message-Id: <m13d9xkkbk.fsf@halfdome.holdit.com>

>>>>> "James" == James Weisberg <chadbour@wwa.com> writes:

James>    Here's a simple challenge.  
 
James>    Given the days of the week: Sun, Mon, Tue, Wed, Thu, Fri, Sat
James> I would like to take various permuations and sequences of those strings 
James> and fill the days in between. Examples: 

James> Sun-Sat = "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
James> Mon-Sun = "Mon,Tue,Wed,Thu,Fri,Sat,Sun"
James> Wed-Tue = "Wed,Thu,Fri,Sat,Sun,Mon,Tue"
James> etc, and sub-sequences:
James> Sun-Tue = "Sun,Mon,Tue"
James> Fri-Sun = "Fri,Sat,Sun"
James> etc.

James>    So a function like fill($from, $to) would fill up to seven days 
James> $from - $to and $from != $to so Mon-Mon, for example, is invalid.

James> Is there a clever solution for this?

Hmm.  This sounds like a great homework problem.  I think I'll assign
it to my class (google for "OGI503").  Thanks!

If it's not a homework problem, you'll need to provide a little more
context.

print "Just another Perl hacker,"

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


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

Date: Wed, 23 May 2001 00:15:48 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Permuting days of the week
Message-Id: <slrn9gm09k.r3e.abigail@tsathoggua.rlyeh.net>

James Weisberg (chadbour@wwa.com) wrote on MMDCCCXXI September MCMXCIII
in <URL:news:T2yO6.6074$DW1.277295@iad-read.news.verio.net>:
\\  
\\     Here's a simple challenge.  
\\   
\\     Given the days of the week: Sun, Mon, Tue, Wed, Thu, Fri, Sat
\\  I would like to take various permuations and sequences of those strings 
\\  and fill the days in between. Examples: 
\\  
\\  Sun-Sat = "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
\\  Mon-Sun = "Mon,Tue,Wed,Thu,Fri,Sat,Sun"
\\  Wed-Tue = "Wed,Thu,Fri,Sat,Sun,Mon,Tue"
\\  etc, and sub-sequences:
\\  Sun-Tue = "Sun,Mon,Tue"
\\  Fri-Sun = "Fri,Sat,Sun"
\\  etc.
\\  
\\     So a function like fill($from, $to) would fill up to seven days 
\\  $from - $to and $from != $to so Mon-Mon, for example, is invalid.
\\  
\\  Is there a clever solution for this?


Assuming the two days are parameters:

    #!/opt/perl/bin/perl -wl
    use strict;
    my @days   = (qw /Sun Mon Tue Wed Thu Fri Sat/) x 2;
    my %days   =  map {$days [$_] => $_} 0 .. 6;
    @ARGV      =  map {$days {$_}} @ARGV;
    $ARGV [1] +=  7 if $ARGV [1] < $ARGV [0];
    print join "," => @days [$ARGV [0] .. $ARGV [1]];
    __END__


Abigail
-- 
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:


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

Date: Wed, 23 May 2001 00:26:06 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Permuting days of the week
Message-Id: <ysDO6.58146$I5.12614326@news1.rdc1.tn.home.com>

Here's your homework because I was bored. Take out my name when you turn in
the source. Tell me what you get on it:

#!/usr/bin/perl

@a = qw( mon 1 tue 2 wed 3 thu 4 fri 5 sat 6 sun 7 );

%d_n = @a;
%n_d = reverse @a;

print join ', ', fill($ARGV[0], $ARGV[1]);

sub fill($$) {
    ($s, $e) = @d_n{$_[0], $_[1]};
    return 0 unless $s and $e and $s != $e;

    $e += 7 if $e < $s;

    for ($s..$e) {
        $_ -= 7 if $_ > 7;
        push @ret, $n_d{$_};
    }

    @ret;
}

-todd




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

Date: Tue, 22 May 2001 17:28:22 -0700
From: David Ball <dball@bnb-lp.com>
Subject: setting priority from perl on linux
Message-Id: <3r0mgt812pitutfsdoim8jj2jget9c4tt4@4ax.com>

Hello,

	I have a perl cgi script that searches 5000 documents for a text
phrase. I'd like to set it to run with a low priority so it doesn't
interfere with other things on the server. Is there a way for a perl
CGI script running on linux to change it's priority ? 

Thanks,

-- David Ball

-----------------------------------------------------
David Ball                      dball@bnb-lp.com
http://www.booksnbytes.com/  (over 2700 author pages)
Book Release Schedule  http://www.booksnbytes.com/pubdate/index.html


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

Date: 22 May 2001 19:37:51 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: setting priority from perl on linux
Message-Id: <87itisyk68.fsf@limey.hpcc.uh.edu>

>> On Tue, 22 May 2001 17:28:22 -0700,
>> David Ball <dball@bnb-lp.com> said:

> Hello, I have a perl cgi script that searches 5000
> documents for a text phrase. I'd like to set it to run
> with a low priority so it doesn't interfere with other
> things on the server. Is there a way for a perl CGI
> script running on linux to change it's priority ?
                                    (its: no apostrophe)

You just have to be nice!

    perldoc POSIX

       nice

Building some kind of database index would be a better way
of doing this, otherwise you'd have at least linear search
time for *every* access.

hth
t
-- 
Just reach into these holes.  I use a carrot.


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

Date: 22 May 2001 17:39:04 -0700
From: usenet@cox99.screaming.net (Graham Cox)
Subject: Sorting data file on numerical field
Message-Id: <47822576.0105221639.7a8cf95@posting.google.com>

I have a data file that I am trying to display as an HTML table from a
CGI script. What I want to do is to sort the data file on the 6th
column before displaying it. The problem is that what little code I've
been able to put together seems to insist on sorting is as if the 6th
column was text, when I need to sort it as a number. Help :)

The data file I'm trying to sort is as follows:

a|1|2|3|4|5
bob|5|4|3|2|1
c|3|5|8|1|8
d|99|99|99|99|99
e|42|24|42|24|62

-- 
Graham

An' Ye harm none, 
do as Ye will.


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

Date: 22 May 2001 19:44:35 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Sorting data file on numerical field
Message-Id: <87heycki6k.fsf@limey.hpcc.uh.edu>

>> On 22 May 2001 17:39:04 -0700,
>> usenet@cox99.screaming.net (Graham Cox) said:

> I have a data file that I am trying to display as an
> HTML table from a CGI script. What I want to do is to
> sort the data file on the 6th column before displaying
> it. The problem is that what little code I've been able
> to put together seems to insist on sorting is as if the
> 6th column was text, when I need to sort it as a
> number. Help :)

Well, it's rather difficult without seeing any code (hint)
but I'd guess the answer is

       <=>

perldoc perlop

hth
t
-- 
Just reach into these holes.  I use a carrot.


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

Date: Tue, 22 May 2001 23:25:55 GMT
From: Lars.Plessmann@gmx.de (Lars)
Subject: This String Formation does not work properly, pleaze help!
Message-Id: <3b0af4ae.12124850@news.btx.dtag.de>

Heres my routine, that makes mistakes if you use big numbers >= 1000.
It works only with little numbers up to 999 I think. Where's the
problem?
I think it's the rounding part. How can I improve it? I don't want
232.333333 or something like that. Only 2 digts after the dot.

sub MoneyFormat
{
 # currency format adding commas for easy read
 my $buf=0;
 local $_ = shift;
 1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
 
 # rounding the currency
 $_=sprintf("%.02f", $_); 

 # Change dots to comma and comma to dots (German form)
 tr/,./.,/;  

 return $_;
}


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

Date: Tue, 22 May 2001 23:47:14 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: This String Formation does not work properly, pleaze help!
Message-Id: <6UCO6.58000$I5.12583148@news1.rdc1.tn.home.com>


"Lars" <Lars.Plessmann@gmx.de> wrote in message
news:3b0af4ae.12124850@news.btx.dtag.de...
> Heres my routine, that makes mistakes if you use big numbers >= 1000.
> It works only with little numbers up to 999 I think. Where's the
> problem?
> I think it's the rounding part. How can I improve it? I don't want
> 232.333333 or something like that. Only 2 digts after the dot.

Once you do the substitution, it's not a number anymore. It's a string with
commas in it. So run it through sprintf first, then seperate the left group
of digits and commify them. put the commified digits back together with the
decimal and the right group of digits, and you're done.




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

Date: Tue, 22 May 2001 22:05:40 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: url parsing
Message-Id: <tglolk8blc923f@corp.supernews.com>

Patrick Joyce (joycefive@earthlink.net) wrote:
: I need a program that takes a url and strips out everything but the
: domain this would normally not be as hard but i need this to work for
: such urls as ".com.au, .co.jp" and "foo.me.com, hi.test.you.com" so if
: my url was http://www.tiac/net/users/candvr
: then i would only want tiac.net.

One way, assuming vanilla http urls:

  ($domain) = $url =~ m!//(.*?)/!;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Tue, 22 May 2001 23:11:45 GMT
From: mmoosler@yahoo.com (Mike Moosler)
Subject: Warning/Danger -- Don't use Perl for CGI
Message-Id: <RmCO6.41$xt5.2043@client>

Here is an excerpt from a publication we get (hopefully this is not a 
copyright violation to post the exerpt here).

Inside Web Development, Mike D. Jones, MCP (ed)
Issue 4 - April 2001
http://www.elementkjournals.com/wdv/0104/

Artical Title: CGI holes for every platform is your server software secure?
by Edgar Danielyan 

### What follows below is an excerpt from the text

Platform: Perl-supported systems /cgi-bin/perl

In general, it’s a very bad idea to use the Perl interpreter as a CGI.

Solution: Remove from cgi-bin

### End of excerpt

I just thought I'd pass this extremely important information to the Perl 
Community.  LoL


FYI:  Here's what their page says about the magazine:

If you're the one who makes business' web
dreams real-Inside Web Development is pure
gold! This all-inclusive journal will help you to
initiate and create the most exciting web
pages ever! 



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

Date: Tue, 22 May 2001 23:25:47 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Warning/Danger -- Don't use Perl for CGI
Message-Id: <%zCO6.57911$I5.12567590@news1.rdc1.tn.home.com>

>
> In general, it's a very bad idea to use the Perl interpreter as a CGI.

Did they say why?




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

Date: Tue, 22 May 2001 23:36:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Warning/Danger -- Don't use Perl for CGI
Message-Id: <g1ulgtg7mk6d2br7df9lrim0i4f988nmk4@4ax.com>

Mike Moosler wrote:

>### What follows below is an excerpt from the text
>
>Platform: Perl-supported systems /cgi-bin/perl
>
>In general, it’s a very bad idea to use the Perl interpreter as a CGI.
>
>Solution: Remove from cgi-bin
>
>### End of excerpt
>
>I just thought I'd pass this extremely important information to the Perl 
>Community.  LoL

I think they mean that it's a bad idea to put the perl executable in
cgi-bin. It is.

-- 
	Bart.


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

Date: 22 May 2001 16:36:57 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Warning/Danger -- Don't use Perl for CGI
Message-Id: <m1bsolklba.fsf@halfdome.holdit.com>

>>>>> "Mike" == Mike Moosler <mmoosler@yahoo.com> writes:

Mike> Platform: Perl-supported systems /cgi-bin/perl

Mike> In general, it’s a very bad idea to use the Perl interpreter as a CGI.

Mike> Solution: Remove from cgi-bin

Mike> ### End of excerpt

Mike> I just thought I'd pass this extremely important information to the Perl 
Mike> Community.  LoL

I suspect they are talking about the outrageously bad installation
of perl into the /cgi-bin of Windows web servers a few years back,
since nobody could figure out how to make .pl run a Perl interpreter.

The downside was that it was trivial to execute any command on any
such-configured webserver.  It wasn't until Tom Christiansen released
his "latro" program (which you can still find by google'ing around)
that anything was done about it, however.

If this is the case, narrowed sufficiently, then I agree with the
text.  However, it does seem possible to interpret this text more
broadly as "no Perl scripts at all", which I would disagree with.

print "Just another Perl hacker,"

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


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 962
**************************************


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