[17447] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4867 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 11 03:05:49 2000

Date: Sat, 11 Nov 2000 00:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973929909-v9-i4867@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 11 Nov 2000     Volume: 9 Number: 4867

Today's topics:
        [announce] IPTC image info extractor module (IPTCInfo.p <josh@spies.com>
    Re: Are # comments really comments? (Alan Barclay)
        expat <singhd@lucent.com>
    Re: grep and reg exp question (Gwyn Judd)
    Re: grep and reg exp question <flavell@mail.cern.ch>
    Re: grep and reg exp question (Gwyn Judd)
    Re: How to force MSDOS window to stay open after perl? <sbakker@home.nl>
        Mark CPAN modules as suspect? (Chris Fedde)
    Re: module install problems with perl2exe on solaris (Maggert)
        New to Perl. How do you do a shell command? <angela.duane@storigen.com>
    Re: pack result - can someone please explain ? <ddunham@redwood.taos.com>
        Perl for Win95 (gb)
    Re: Perl for Win95 (Maggert)
        Premature end of script headers? <m00fbe01@NOSPAMmcmail.com>
    Re: Premature end of script headers? <bwalton@rochester.rr.com>
    Re: Premature end of script headers? (David Efflandt)
    Re: Pushing a hash on to a stack... <ren.maddox@tivoli.com>
    Re: Random Array with Sort? (Gwyn Judd)
    Re: Random Array with Sort? <quantum_mechanic@my-deja.com>
    Re: Random Array with Sort? (Gwyn Judd)
    Re: Self-modifying code in Perl (Ilya Zakharevich)
    Re: Self-modifying code in Perl (Martien Verbruggen)
    Re: Self-modifying code in Perl (Alan Barclay)
    Re: Self-modifying code in Perl (Ilya Zakharevich)
    Re: udp server - high volume - log switch fw58959@hotmail.com
    Re: Using POST and POST/ACTION on the same page - I fig <radar@jetstream.net>
        Using POST and POST/ACTION on the same page <radar@jetstream.net>
    Re: VBScript to perl converter? <ronnie@catlover.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 10 Nov 2000 22:43:54 -0700
From: Josh Carter <josh@spies.com>
Subject: [announce] IPTC image info extractor module (IPTCInfo.pm)
Message-Id: <josh-A409A0.22435410112000@news.mindspring.com>

Fellow Perl folks,

I've been forever wanting a Perl module to extract IPTC info from
image files. Finally I gave up, got the spec, and wrote it myself. I'm
making it available at:

http://multipart-mixed.com/photo/iptc.html

Background info: "IPTC info" refers to image metadata like caption,
byline, keywords, etc. embedded in the file. This is what Photoshop's
"File->File Info" menu item lets you add -- it's the standard used by
news agencies worldwide. This module lets you extract it. Not only
that, but you can export the data as XML, and also export SQL
statements ready to feed to your favorite database. See the web page
for more information.

You may also be interested in gxml2html, my generic tool for easily
transforming XML into HTML. This pairs up well with the above module's
XML export feature -- it's a piece of cake to generate HTML files for
your images, using IPTC info embedded in them. See:

http://multipart-mixed.com/xml/

Both are free software, to be distributed under the same terms as
Perl. At some point I'll look into submitting the IPTC module to CPAN;
right now I'm unfamiliar with that process. (Comments on how to do
this are welcome.) Please also send me bug reports, feature requests, 
etc..

Pedantic note: "IPTC info" is a misnomer just like "PCMCIA card."
IPTC, as with PCMCIA, is the name of the standards organization which
defines a very useful standard. The stardard in question here is IIM,
"Information Interchange Model" version 4. For the sake of being
consistent with what people usually call it, I've named the module
IPTCInfo.

Best regards,
Josh


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

Date: 11 Nov 2000 04:14:06 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Are # comments really comments?
Message-Id: <973916010.993427@elaine.furryape.com>

In article <8uh6n8$pp7$1@murdoch.acc.Virginia.EDU>,
Doug Coppage <dpc3k@virginia.edu> wrote:
>often yields "runaway string" errors several lines down. Erasing these
>erstwhile comments from my source code eliminates the problem. Also, it
>seems that the two characters '<' and '>' cannot be safely used in
>commented-out print statements, either.

Are you sure you're actually doing comments? If you have a missing
quote earlier in the program, then the string will continue until it
is matched. For example this program compiles and runs:

#!/usr/local/bin/perl -w
# this is a comment with a '

print "This is the start of a print
# this is not a comment with a "  
# this is     a comment with a "


The quote is matched properly, even thought the line begins with a #,
because at that time you are within a double quoted string begining
on the print line. However, the single quote on the first line, and
the double quote on the last line are part of true comments, and
therefore ignored.


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

Date: Fri, 10 Nov 2000 11:46:40 +0000
From: Daywan Singh <singhd@lucent.com>
Subject: expat
Message-Id: <3A0BE020.CDA21DA2@lucent.com>

I have a problem with the installation of the Perl module expat-1.95.1 on SunOS
5.8

I manage to run the following command successfully:

 ./configure

but when I come to run 'make', I get the following error

cc -DHAVE_CONFIG_H -DPACKAGE=\"expat\" -DVERSION=\"expat_1.95.1\" -I. -I.. -g
-Wp,-MD,.deps/xmlparse.pp -c xmlparse.c  -KPIC -DPIC -o xmlparse.o
command line: fatal: invalid arg for option M  D: No such file or directory
cc: acomp failed for xmlparse.c
*** Error code 1
make: Fatal error: Command failed for target `xmlparse.lo'


Has anyone else try to install this module? I need to install this module in
order to use XML::DOM.

I tried raising a bug report at http://sourceforge.net/bugs but to noavail.

D Singh
singhd@lucent.com


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

Date: Fri, 10 Nov 2000 23:52:38 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: grep and reg exp question
Message-Id: <slrn90p2i0.c31.tjla@thislove.dyndns.org>

I was shocked! How could Helgi Briem <helgi@NOSPAMdecode.is>
say such a terrible thing:
>On Fri, 10 Nov 2000 04:09:13 GMT, tjla@guvfybir.qlaqaf.bet
>(Gwyn Judd) wrote:

>>In that case I would probably use the DBD::CSV module which is designed
>>to split CSV file like this, rather than just using grep(1) which isn't.
>>
>or alternatively:
>
>	my ($first,$last,$phone,$email,$address,$labphone,$super)
>= split (/,/,$_);

That only works as long as there are no comma's as part of a field
(inside the double quotes). DBD::CSV allows for that, yours doesn't.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
"Low probability is not a miracle, merely a statistic."
         [Justin Thomas (just@infoave.net)]
  Atheism/Freethought fortune cookie file


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

Date: Sat, 11 Nov 2000 01:26:04 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: grep and reg exp question
Message-Id: <Pine.GHP.4.21.0011110123570.27696-100000@hpplus03.cern.ch>

On Fri, 10 Nov 2000, Gwyn Judd wrote:

> That only works as long as there are no comma's as part of a field

And _that_ only works as long as there are no greengrocer's put i'n
cha'rge of apostrophe's...




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

Date: Sat, 11 Nov 2000 04:23:22 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: grep and reg exp question
Message-Id: <slrn90pido.dck.tjla@thislove.dyndns.org>

I was shocked! How could Alan J. Flavell <flavell@mail.cern.ch>
say such a terrible thing:
>
>And _that_ only works as long as there are no greengrocer's put i'n
>cha'rge of apostrophe's...

Pedant

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
"Earth is a great, big funhouse without the fun."
		-- Jeff Berner


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

Date: Sat, 11 Nov 2000 07:32:51 GMT
From: Sjoerd Bakker <sbakker@home.nl>
Subject: Re: How to force MSDOS window to stay open after perl?
Message-Id: <2gsp0tkh78ktikb4vtmgv4bqap6j8uj3vk@4ax.com>

The closing of the Dos-box annoyed me too, so I wrote a little
C-program to let it stay open until you pres a key. Works great...
just compile it to Perl.exe, rename your original Perl.exe in the bin
directory to Perl-org.exe and put the new Perl.exe there instead.


Sjoerd


/* Perl.c for Win32
   Enables the DOS-window to stay open after
   executing a Perl-script by double-clicking on it.

   Rename Perl.exe in the bin directory to
   Perl-org.exe, compile this program to Perl.exe
   and put it there instead.
*/   

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <process.h>


/* This puts quotes around the arguments, otherwise
   they would be split if they contain spaces.
*/

void argv_to_nargv (char *argv[], char *nargv[], char *s)
{
int i;

for (i=0; argv[i]; i++) {
	nargv[i] = s;
	s[0] = '"';
	strcpy (&s[1], argv[i]);
	s += (strlen (argv[i]) + 3);
	s[-2] = '"';
	s[-1] = '\0';
	}
nargv[i] = NULL;
}


int main (int argc, char *argv[])
{

/* Allocate more space for arguments if you need it.
*/

char *nargv[100], s[1000];

int retval;

argv_to_nargv (argv, nargv, s);

retval = spawnvp (P_WAIT, "Perl-org.exe", nargv);

printf ("\n\nPress a key to finish...");
getch ();

return (retval);
}


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

Date: Sat, 11 Nov 2000 05:49:55 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Mark CPAN modules as suspect?
Message-Id: <765P5.313$Bf7.170838528@news.frii.net>

[A cc of this posting was forwarded to Hank Barta]

On Fri, 10 Nov 2000 10:41:24 -0600 (CST)  Hank Barta wrote:
 +------------------
 | On Fri, 10 Nov 2000, Chris Fedde wrote:
 |
 | > This brings up an interesting issue.  Is there a way to globally
 | > mark CPAN modules as suspect?   I'll post on this subject and see
 | > if there is any net wide interest.
 |
 |     I think it would be adequate to put a comment in the POD....
 |     Just checked and it seems to be there. Perhaps another way
 |     would be to add a 'standard file' (ala 'INSTALL' 'README' and
 |     so on) called BUGS. I think I would prefer some sort of internal
 |     notation rather than flagging them at CPAN. That way no matter
 |     how I get the package, the information would be there.
 +------------------

You know, after mulling this about for the last few hours I begin
to think that "caveat utilitor" is probably the best approach
after all.  Initially I was thinking on the lines of a central
registry of user supplied test code, indexed by module name.  But
I now think the potential for abuse and slander is too great.

I'm posting this to c.l.p.m to see if anyone else has a comment.

Oh well
chris


-- 
    This space intentionally left blank


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

Date: Sat, 11 Nov 2000 05:21:00 GMT
From: mag@ionet.net (Maggert)
Subject: Re: module install problems with perl2exe on solaris
Message-Id: <3a0cd6c0.985967@news.ionet.net>

On Fri, 10 Nov 2000 22:00:00 GMT, akcrum@my-deja.com wrote:

>Hi -
>
>I'm using perl2exe on a Solaris (SunOS) platform.
>I'm in need of the Storable.pm module
>(but this problem is not limited to a particular module).
>My attempt to do 'perl Makefile.PL' as 1st step of install results in:
>---
>Error: Unable to locate installed Perl libraries or Perl source code.
>...
>(You get this message, because MakeMaker could not
>find "/users/is/isingh/p2x553/SunOS/perl2exe/perl5/lib/5.00503/sun4-
>solaris/CORE/perl.h")
>---
>
	Perl2exe has it's own perl binaries. You need to copy
Storable.pm to the location its supposed to be in that binary. It
doesn't use the Perl thats already on your system.


MP


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

Date: Sat, 11 Nov 2000 03:40:48 GMT
From: Angela Duane <angela.duane@storigen.com>
Subject: New to Perl. How do you do a shell command?
Message-Id: <3A0CBF78.A2F3510E@storigen.com>

I found about 1/2 page in one of my Perl books
that describes how to do Shell things. I can't
believe that this is such an uncommon thing to do.
Anyway, I was playing with it and I can't get it
to work?

use Shell qw(dd);     #list shell commands script
will be using
dd ("if=/dev/zero", "of=$FileName", "bs=512k",
"size=$SizeOfFile");

It looks in the book that arguments need to have
commas between each argument and "" and that flags
need "", but should not have commas between them.

I can get the code to compile, but when the second
line is executed I get a message something like:

dd:  dd if=/dev/zero of=$FileName bs=512k
size=$SizeOfFile: file doesn't exist. (something
like that)

Am I missing something for the syntax? I have
tried very simple things like trying to cat a file
or ls and I get similar results. Help me?!





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

Date: Sat, 11 Nov 2000 00:13:03 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: pack result - can someone please explain ?
Message-Id: <ja0P5.1032$dm6.114122@news.pacbell.net>

Gerd Bavendiek <bav@esn.sbs.de> wrote:
> Hi,

> this is my small program:

> lulu:/home/bav/wsp/eurodial> cat t6
> #!/usr/bin/perl
> print pack("cc", 9, 10);
> print pack("hh", 0x09, 0x0a);

> lulu:/home/bav/wsp/eurodial> od -c qqq
> 0000000  \t  \n  \t 001
> 0000004

> which really surprises me. Can please someone explain ?

It's tricky.  You have to notice in the docs that 'h' and 'H' take a
hexadecimal *string* and not numbers.

You need to specify "a", not the numeric 10 or 0xa for the 1010 bit
pattern.

perl -e 'print unpack "hh", (pack "hh", 10, "a")'
1a

So in your example, 10 is turned into the string "10", which pack eats
as "1".
-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
      < Please move on, ...nothing to see here,  please disperse >


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

Date: Sat, 11 Nov 2000 04:18:55 GMT
From: gbnews@arcticmail.com (gb)
Subject: Perl for Win95
Message-Id: <3a0cc77e.33042490@news.lineone.net>

Hello!

I've never done anything with perl yet but I'm looking to start.

Can anyone tell me what software is best for Win95 and a tutorial for
installation and a beginning tutorial for perl.

I have Perl 5 on cd but no instructions on how to install. I had a
look at the ActiveState perl 5.6 web page. This seems quite
complicated to set up and a 5mb download.

Can anyone tell me how to get started using Win95?

Thanks,
Gary


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

Date: Sat, 11 Nov 2000 05:28:26 GMT
From: mag@ionet.net (Maggert)
Subject: Re: Perl for Win95
Message-Id: <3a0cd884.1437577@news.ionet.net>

On Sat, 11 Nov 2000 04:18:55 GMT, gbnews@arcticmail.com (gb) wrote:

>Hello!
>
>I've never done anything with perl yet but I'm looking to start.
>
>Can anyone tell me what software is best for Win95 and a tutorial for
>installation and a beginning tutorial for perl.
>
>I have Perl 5 on cd but no instructions on how to install. I had a
>look at the ActiveState perl 5.6 web page. This seems quite
>complicated to set up and a 5mb download.
>
	Very complicated! Double clicking is so hard to do now days.
What with two buttons on the mouse it's hard to decide which one to
click twice.


MP


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

Date: Sat, 11 Nov 2000 03:21:16 +0000
From: Steve <m00fbe01@NOSPAMmcmail.com>
Subject: Premature end of script headers?
Message-Id: <3A0CBB2C.6DB3@NOSPAMmcmail.com>

Hi All,

I'm pulling my hair out on this one and have spent
several hours on it. Basically I installed a Perl
script on a test server and everything worked ok.
I've now just installed it in its proper location
but all i'm getting is the helpful 'Premature end of
script headers' I have checked all the permissions
on files/directories - i've removed all the files and
checked again that they were uploaded in ascii. I've
even checked the directory structure as it is *slightly*
different than on the test server. All to no avail even
though the program ran fine on the other server - i've
not made any other changes other than to move it to its
new location.

Is there a way of getting more useful info as to where
exactly the problem is i.e. The perl script has a 
few files that are required and I suppose the problem
could be either in any of these three files or with the
Perl script itself - it's a case of finding where exactly
the problem lies.

Any Ideas anyone?


Cheers in advance for any help.

Steve


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

Date: Sat, 11 Nov 2000 04:00:59 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Premature end of script headers?
Message-Id: <3A0CC54A.FC896849@rochester.rr.com>

Steve wrote:
 ...
> I'm pulling my hair out on this one and have spent
> several hours on it. Basically I installed a Perl
> script on a test server and everything worked ok.
> I've now just installed it in its proper location
> but all i'm getting is the helpful 'Premature end of
> script headers' I have checked all the permissions
> on files/directories - i've removed all the files and
> checked again that they were uploaded in ascii. I've
> even checked the directory structure as it is *slightly*
> different than on the test server. All to no avail even
> though the program ran fine on the other server - i've
> not made any other changes other than to move it to its
> new location.
> 
> Is there a way of getting more useful info as to where
> exactly the problem is i.e. The perl script has a
> few files that are required and I suppose the problem
> could be either in any of these three files or with the
> Perl script itself - it's a case of finding where exactly
> the problem lies.
 ...
> Steve
Well, assuming you are using the CGI module, try:

    use CGI::Carp 'fatalsToBrower';
-- 
Bob Walton


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

Date: Sat, 11 Nov 2000 04:12:17 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Premature end of script headers?
Message-Id: <slrn90phok.btl.efflandt@efflandt.xnet.com>

On Sat, 11 Nov 2000 03:21:16 +0000, Steve <m00fbe01@NOSPAMmcmail.com> wrote:
>
>I'm pulling my hair out on this one and have spent
>several hours on it. Basically I installed a Perl
>script on a test server and everything worked ok.
>I've now just installed it in its proper location
>but all i'm getting is the helpful 'Premature end of
>script headers' I have checked all the permissions
>on files/directories - i've removed all the files and
>checked again that they were uploaded in ascii. I've
>even checked the directory structure as it is *slightly*
>different than on the test server. All to no avail even
>though the program ran fine on the other server - i've
>not made any other changes other than to move it to its
>new location.
>
>Is there a way of getting more useful info as to where
>exactly the problem is i.e. The perl script has a 
>few files that are required and I suppose the problem
>could be either in any of these three files or with the
>Perl script itself - it's a case of finding where exactly
>the problem lies.
>
>Any Ideas anyone?

First make sure that you have a proper path to perl (make sure that you 
can get a simple script to run).  Then you could try either:

use CGI::Carp qw(fatalsToBrowser);

Or put a Perl wrapper around the script that can show you any error
messages if it will not even precompile:

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print `./other.cgi 2>&1`	# those are backticks, not quotes

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 10 Nov 2000 16:15:47 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Pushing a hash on to a stack...
Message-Id: <m366lvjwx8.fsf@dhcp11-177.support.tivoli.com>

craznar@hotmail.com (Christopher Burke) writes:

> ren.maddox@tivoli.com (Ren Maddox) wrote in
> <m366lxlvyp.fsf@dhcp11-177.support.tivoli.com>: 
>
> >And these two lines use references.  $fulldata[0] holds a reference to
> >a hash.  $fulldata[0]{x} is just a shorthand for $fulldata[0]->{x},
> >which is, itself, a shorthand for ${$fulldata[0]}{x}.
> >There be references here....
> 
> Well I cannot see any references there, must mean I just have different 
> words to express things. That language difference seems to have cursed me 
> in this newsgroup. 

Ah, okay.  So do you only care about references used in a particular
way, or do you really care if there are references even if they are
not obvious?

> >  push @fulldata, \%hash;     # but do not reuse the same %hash
> 
> That one doesn't work ... because, even with creating new %hash each loop.

Looks like you might not have finished this thought.  It seems that
you started to say why this wouldn't work, but didn't actually say it.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Sat, 11 Nov 2000 00:58:17 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Random Array with Sort?
Message-Id: <slrn90p6d5.c31.tjla@thislove.dyndns.org>

I was shocked! How could Quantum Mechanic <quantum_mechanic@my-deja.com>
say such a terrible thing:
>Someone asked me the "random array" question again. I of course pointed
>them to perlfaq4, etc.
>
>However, I started thinking about the Fisher/Yates Shuffle, and wondered
>if its running time could be improved but still be unbiased (each
>permutation is equally likely). Fisher/Yates is O(n^2), while quicksort
>is O(n.log(n)).

Are you sure about that? At a cursory examination, Fisher/Yates appears
to go through the array only once, from top to bottom, which would make
it linear.

>On a whim I tried:
>
>  @array = sort { -rand( 2 ) } @array;
>
>This seems to be about twice as fast as F/Y (and grows less quickly).

I would have (did) used sort { int rand( 3 ) - 1 } since this gives you
positive and negative values for the comparision function.

>However, this is highly biased. Also, for arrays >= 7 elements, most
>permutations never appear, regardless of how many trials are run
>(probably due to efficiencies of sort ;).

#!/usr/bin/perl -w

sub fisher_yates_shuffle {
   my $array = shift;
   my $i;
   for ($i = @$array; --$i; ) {
       my $j = int rand ($i+1);
       next if $i == $j;
       @$array[$i,$j] = @$array[$j,$i];
   }
}

@array = 1..20000;
@results = (0) x @array;

for $n (1..200)
{
    # @randarray = sort { int rand( 3 ) - 1 } @array;
    @randarray = @array;
    fisher_yates_shuffle \@randarray;

    for ($i = 0; $i < @randarray; $i++)
    {
        $results[$i] = ($results[$i] * ($n - 1) +
                        $randarray[$i]) / $n;
    }
}

foreach (@results)
{
    print "$_\n";
}

If you run the results of this through gnuplot (or equivalent) the two
different pictures are...interestingly different. No idea why though.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Make your life a mission -- not an intermission.
-Glasgow


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

Date: Sat, 11 Nov 2000 03:24:35 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Re: Random Array with Sort?
Message-Id: <8uie5f$6fv$1@nnrp1.deja.com>

In article <slrn90p6d5.c31.tjla@thislove.dyndns.org>,
  tjla@guvfybir.qlaqaf.bet (Gwyn Judd) wrote:
> I was shocked! How could Quantum Mechanic
<quantum_mechanic@my-deja.com>
> say such a terrible thing:
> >Someone asked me the "random array" question again. I of course
pointed
> >them to perlfaq4, etc.
> >
> >However, I started thinking about the Fisher/Yates Shuffle, and
wondered
> >if its running time could be improved but still be unbiased (each
> >permutation is equally likely). Fisher/Yates is O(n^2), while
quicksort
> >is O(n.log(n)).
>
> Are you sure about that? At a cursory examination, Fisher/Yates
appears
> to go through the array only once, from top to bottom, which would
make
> it linear.

Sorry, you're right. I've been staring at this too long.

>
> >On a whim I tried:
> >
> >  @array = sort { -rand( 2 ) } @array;
> >
> >This seems to be about twice as fast as F/Y (and grows less quickly).
>
> I would have (did) used sort { int rand( 3 ) - 1 } since this gives
you
> positive and negative values for the comparision function.
>
> >However, this is highly biased. Also, for arrays >= 7 elements, most
> >permutations never appear, regardless of how many trials are run
> >(probably due to efficiencies of sort ;).
>

Concerning { int rand( 3 ) - 1 } vs. { -rand( 2 ) }...

Actually, I should have used "int"...or maybe it doesn't matter.

As to my choice of { -rand( 2 ) }, what happens when it returns 0? The
values are "equal". 1? $a > $b. What is the difference to sort? Probably
nothing. So { int rand( 3 ) - 1 } only "exchanges" 1 out of 3 times. {
int rand( 2 ) - 1 } exchanges 1 out of 2 times. { - int rand( 2 ) } is
equivalent to that (if I'm not smoking something I shouldn't be).

So, why does sort run faster? Probably the constant for F/Y is higher,
because it is in Perl, and sort is in C.

Any grand ideas along these lines?

-QM

--
Quantum Mechanics: The dreams stuff is made of.


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


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

Date: Sat, 11 Nov 2000 04:51:14 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Random Array with Sort?
Message-Id: <slrn90pk1v.dck.tjla@thislove.dyndns.org>

I was shocked! How could Quantum Mechanic <quantum_mechanic@my-deja.com>
say such a terrible thing:

>Concerning { int rand( 3 ) - 1 } vs. { -rand( 2 ) }...
>
>Actually, I should have used "int"...or maybe it doesn't matter.
>
>As to my choice of { -rand( 2 ) }, what happens when it returns 0? The
>values are "equal". 1? $a > $b. What is the difference to sort? Probably
>nothing. So { int rand( 3 ) - 1 } only "exchanges" 1 out of 3 times. {
>int rand( 2 ) - 1 } exchanges 1 out of 2 times. { - int rand( 2 ) } is
>equivalent to that (if I'm not smoking something I shouldn't be).

If I do this: 

sort { rand( 1001 ) - 500 }

Then the shuffle appears to be pretty good, just by looking at the
scatterplot. The larger number you use in the sort function, the better
the results seem to be. As you choose larger numbers, the odds that a
number is swapped moves closer to 1/2, whereas when you have smaller
numbers the likelihood is closer to 1/3. With a small likelihood that a
number is going to be swapped, most numbers are not going to be swapped
at all, which explains the general shape of the graph. I'm not sure why
the numbers at the ends seem to be shuffled more effectively than the
numbers in the middle though.

>So, why does sort run faster? Probably the constant for F/Y is higher,
>because it is in Perl, and sort is in C.

Actually when I timed it just now, sort does not appear to be faster at
all.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
BOFH excuse #299:

The data on your hard drive is out of balance.


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

Date: 11 Nov 2000 00:07:54 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Self-modifying code in Perl
Message-Id: <8ui2kq$ope$1@charm.magnus.acs.ohio-state.edu>
Keywords: raft, seedling, shimmy, singsong

[A complimentary Cc of this posting was sent to Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>],
who wrote in article <8ugpbb$57f$1@lublin.zrz.tu-berlin.de>:
> An alternative I like to bring up at this point:
> 
>    read CODE, $_, -s CODE;

This assumes some relationship between what -s CODE returns and the
amount of characters read from CODE.  There should be none given some
translations may be performed behind the scene.

Ilya


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

Date: Sat, 11 Nov 2000 15:21:53 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Self-modifying code in Perl
Message-Id: <slrn90pib1.gs3.mgjv@martien.heliotrope.home>

On 11 Nov 2000 00:07:54 GMT,
	Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was sent to Anno Siegel
><anno4000@lublin.zrz.tu-berlin.de>],
> who wrote in article <8ugpbb$57f$1@lublin.zrz.tu-berlin.de>:
>> An alternative I like to bring up at this point:
>> 
>>    read CODE, $_, -s CODE;
> 
> This assumes some relationship between what -s CODE returns and the
> amount of characters read from CODE.  There should be none given some
> translations may be performed behind the scene.

If you hadn't pointed that oiut, I probably would have. pedantically
speaking, that is of course true, however...

On the other hand, the only thing possible is that '-s CODE' is larger
than the buffer needed to actually read it. What you end up with is a
LENGTH argument to read() that is not going to be too small. You'll read
fewer bytes on systems where newline translates to multiple characters,
or if you're working with multibyte characters (does read() care?) or
so, but that's not a problem. The read should terminate early on eof,
and it'll nicely inform you how many characters it actually did read,
in case you want to know.

It's an idiom which is often enough used in C, where a large enough
buffer needs to be allocated before you can do a one-off read. It may be
wasteful there. It probably isn't in Perl.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


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

Date: 11 Nov 2000 07:15:31 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Self-modifying code in Perl
Message-Id: <973926871.954511@elaine.furryape.com>

In article <slrn90pib1.gs3.mgjv@martien.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>On 11 Nov 2000 00:07:54 GMT,
>	Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>> [A complimentary Cc of this posting was sent to Anno Siegel
>><anno4000@lublin.zrz.tu-berlin.de>],
>> who wrote in article <8ugpbb$57f$1@lublin.zrz.tu-berlin.de>:
>>> An alternative I like to bring up at this point:
>>> 
>>>    read CODE, $_, -s CODE;
>> 
>> This assumes some relationship between what -s CODE returns and the
>> amount of characters read from CODE.  There should be none given some
>> translations may be performed behind the scene.
>
>If you hadn't pointed that oiut, I probably would have. pedantically
>speaking, that is of course true, however...
>
>On the other hand, the only thing possible is that '-s CODE' is larger
>than the buffer needed to actually read it. What you end up with is a
>LENGTH argument to read() that is not going to be too small. You'll read

Is it not possible that in record orientated files, on OS's which support
them, may have no end of line characters on disk, but do contain them
when read through a stream?


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

Date: 11 Nov 2000 07:25:57 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Self-modifying code in Perl
Message-Id: <8uisa5$487$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was NOT sent to Martien Verbruggen
<mgjv@tradingpost.com.au>],
who wrote in article <slrn90pib1.gs3.mgjv@martien.heliotrope.home>:
> > This assumes some relationship between what -s CODE returns and the
> > amount of characters read from CODE.  There should be none given some
> > translations may be performed behind the scene.

> On the other hand, the only thing possible is that '-s CODE' is larger
> than the buffer needed to actually read it

 ... on the systems we know...

> It's an idiom which is often enough used in C

 ... but C code is infinitely less portable than Perl code.  Let's keep
it so.  Do not use such suspicious code in Perl...

Ilya


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

Date: Sat, 11 Nov 2000 03:48:23 GMT
From: fw58959@hotmail.com
Subject: Re: udp server - high volume - log switch
Message-Id: <8uifi7$7fm$1@nnrp1.deja.com>

In article <TqDO5.278$Bf7.188635136@news.frii.net>,
  cfedde@fedde.littleton.co.us (Chris Fedde) wrote:
> In article <t5uO5.1154$FG.62261@eagle.america.net>,
> Garry Williams <garry@zvolve.com> wrote:
> >On Thu, 09 Nov 2000 05:47:04 GMT, Chris Fedde
> ><cfedde@fedde.littleton.co.us> wrote:
> >>In article <8udbg8$12d$1@nnrp1.deja.com>,  <fw58959@hotmail.com>
> >>wrote:
> >...
> >>
> >>    sub checkhup {
> >>	if ($GotHup) {
> >>	    close LOG;
> >>	    open (LOG, ">>log") or die "can't open log: $!";
> >>	}
> >>    }
> >
> >    sub checkhup {
> >	if ($GotHup) {
> >	    close LOG;
> >	    open (LOG, ">>log") or die "can't open log: $!";
> >	    $GotHup = 0;
> >	}
> >    }
> >
>
> Oops!  thanks for the catch!
>
> chris
> --
>     This space intentionally left blank
>

Thank you for all your help.   I have implemented this and it appears to
work just great!.

Cheers,

 ./CK


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


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

Date: Fri, 10 Nov 2000 23:55:38 -0800
From: "Dragonia Radar Freedom, C.S." <radar@jetstream.net>
Subject: Re: Using POST and POST/ACTION on the same page - I figured it out
Message-Id: <3A0CFB7A.B54D896A@jetstream.net>

I figured out my problem 10 minutes after posting this...
a </form> is always a good thing :)

For those interested, here's the updated code:

---------------------
  use strict;
  use CGI qw/:standard/;
  use CGI::Carp qw/fatalsToBrowser/;

  print header, start_html("Testing");

  print "<form method=\"post\">";
  print "Gimme some text<br><input type=\"text\" name=\"Text\"><br>";
  print "<input type=\"Submit\" value=\"Show\"><br><br>";
  print "</form>";

  my $text=param("Text");
  if ($text ne "") {
    print "$text<br>";

    print "<form method=\"post\" action=\"/cgi-bin/display.pl\">";
    print "<input type=\"hidden\" value=\"$text\">";
    print "<input type=\"Submit\" value=\"Display on new page\"><br><br>";
    print "</form>"; }
--------------------

--
Michel.


>



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

Date: Fri, 10 Nov 2000 23:41:43 -0800
From: "Dragonia Radar Freedom, C.S." <radar@jetstream.net>
Subject: Using POST and POST/ACTION on the same page
Message-Id: <3A0CF837.8974AEE1@jetstream.net>

I'm trying to create a dynamic HTML page that will do two things:
1. Dynamically alter the page using my perl script depending on the choices made using POST
2. Load a different perl script using POST and ACTION

Here's my code for testing how to do this:
---------------------
  use strict;
  use CGI qw/:standard/;
  use CGI::Carp qw/fatalsToBrowser/;

  print header, start_html("Techtistics Home Page Builder v1.0 Demo - Advanced Builder");

  print "<form method=\"post\">";
  print "Gimme some text<br><input type=\"text\" name=\"Text\"><br>";
  print "<input type=\"Submit\" value=\"Show\"><br><br>";

  my $text=param("Text");
  if ($text ne "") {
    print "$text<br>";

    print "<form method=\"post\" action=\"/cgi-bin/display.pl\">";
    print "<input type=\"hidden\" value=\"$text\">";
    print "<input type=\"Submit\" value=\"Display on new page\"><br><br>"; }
---------------------
Here's the results:
-when I type something and press <show>, I see the textbox, the show button, the text, then the Display button
-when I then click on <display>, $text=null and I just get the textbox and the show button.

Here's what I want:
-type something and press <show>.  Have $text displayed below the show button
-press <display> and have another script display $text on the page

Why:
-This is an experiement in dynamic HTML coding.  I don't know if this can be done and am trying like heck to figure it out.

Efforts:
-Looked in all my books.  They all do either the dynamic scripting thing or the load another page thing, but not both (is that a
hint?)
-looked in my ActivePerl documentation.  Navigating that is... nasty...
-looked in the Perl FAQ.  Nope
-I've done some quick searching in this group looking for POST and ACTION, but didn't find anything useful
-looked at the archives in Deja News and found squat
-posted this message

---------------------
Any and all help would be greatly appreciated.

Be advised that I have asbestos underwear and can ignore all flames directed at me (I've read a lot of those by posters who
think they're godlike (devillike) and will only flame, not help).  I would like help as my efforts so far have proved futile.

Thanks.

--
Michel.





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

Date: Sat, 11 Nov 2000 04:22:40 GMT
From: Ron Grabowski <ronnie@catlover.com>
Subject: Re: VBScript to perl converter?
Message-Id: <3A0CC96A.DDC08247@catlover.com>

Mr. Matt Sergeant has this on his Perlscript site:

ScriptletConv

This is a small script that converts VB scriptlets to
PerlScript. Scriptlets is a technology that allows
you to author OLE components in scripting
languages that support Active Scripting. See MS
Scripting web site.

http://www.fastnetltd.ndirect.co.uk/Perl/scriptletconv.zip

Converting Perlscript -> Perl shouldn't be to difficult.


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4867
**************************************


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