[17451] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4871 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 12 00:05:43 2000

Date: Sat, 11 Nov 2000 21:05:08 -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: <974005508-v9-i4871@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
        accessing hardware ports with perl under linux i386 + d <nward@nfmail.com>
        Can someone help? <mrNO-SPamerican@hotmail.com>
    Re: getting total in a foreach loop (Gwyn Judd)
    Re: getting total in a foreach loop <theborg@usa.com>
    Re: How to call sub routines from a CGI made Form (Gwyn Judd)
        label not found ? and trailing decimal - still new at t msalerno@my-deja.com
    Re: label not found ? and trailing decimal - still new  msalerno@my-deja.com
    Re: Launching an Long-Term Process in IIS <bwalton@rochester.rr.com>
        Native float translation <kj0@mailcity.com>
        need some help with RE metamp@my-deja.com
    Re: need some help with RE <wyzelli@yahoo.com>
    Re: need some help with RE <stephenk@cc.gatech.edu>
        PERL AND JPGS AND SHOPPING CART <ppdc@home.com>
    Re: Perl for Win95 (gb)
        Please Help  - Student question regarding Flock and Sem <DaveTuring@spam.co.uk>
    Re: Pushing a hash on to a stack... (Christopher Burke)
    Re: Pushing a hash on to a stack... <james@NOSPAM.demon.co.uk>
    Re: Pushing a hash on to a stack... (Christopher Burke)
    Re: Pushing a hash on to a stack... (Anno Siegel)
    Re: Pushing a hash on to a stack... (Christopher Burke)
    Re: Pushing a hash on to a stack... (Garry Williams)
    Re: Random Array with Sort? <james@NOSPAM.demon.co.uk>
    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)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 12 Nov 2000 13:48:06 +1300
From: "Nathan Ward" <nward@nfmail.com>
Subject: accessing hardware ports with perl under linux i386 + daemons
Message-Id: <wSlP5.1142$gVqd.26869852@news.xtra.co.nz>

i am trying to access hardware ports under linux on an i386, I read
somewhere, (coffee howto i think :) )that /dev/port can be used or is there
another way to do it that is faster/better?

The reason i am trying to do this is for a 3x4 matrix keypad and a 2x16 lcd
screen for ppp link status readout and control for my family :)

also, is it possible to make a perl script run as a daemon in the
background? if so how?

Thanx








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

Date: Wed, 08 Nov 2000 13:47:48 -0800
From: Bill <mrNO-SPamerican@hotmail.com>
Subject: Can someone help?
Message-Id: <3A09CA04.52BCA871@hotmail.com>

I am looking for  a way to hide
http://eflashtech.com/user/etrproductions with the web address
http://www.gottagettaflashsite.com so that when you type in
gottagettaflashsite.com you will never see
eflashtech.com/user/etrproductions. Anyone know how that is possible?

I was sent a script that was about 3 lines long some time ago,  but
could not make it work and have since lost it.

I'm not much good with cgi/perl/php/asp etc. so I would really
appreciate some help.

Thanks so much
Bill
You can email  me at Mr-American@hotmail.com remove the - or post back
here someone else might like to learn the trick too.



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

Date: Sat, 11 Nov 2000 23:23:30 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: getting total in a foreach loop
Message-Id: <slrn90rl7h.gvl.tjla@thislove.dyndns.org>

I was shocked! How could Bob <theborg@usa.com>
say such a terrible thing:
>
>--------------8ACB5DF482BD3E9C71145CCA
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit

Please don't do that. This is a text only newsgroup.

>I am looking for a way to get the running total into this little sub. I
>
>foreach my $i (0 .. $#products) {

>  $row_total=sprintf("%4.2f", $row_total);

   $running_total += $row_total;

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Pohl's law: 
	 Nothing is so good that somebody, somewhere, will not hate it.


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

Date: Sun, 12 Nov 2000 00:11:49 GMT
From: Bob <theborg@usa.com>
Subject: Re: getting total in a foreach loop
Message-Id: <3A0DE03F.26D80A52@usa.com>


DOH!!!! Sorry about that. The people I work with are always bitching at
me for not having HTML on so I turned it on.

PS - thanks for the tip it worked perfectly... why I did not think of
that I do not know, I must have been staring too long.

Bob



Gwyn Judd wrote:
> 
> I was shocked! How could Bob <theborg@usa.com>
> say such a terrible thing:
> >
> >--------------8ACB5DF482BD3E9C71145CCA
> >Content-Type: text/plain; charset=us-ascii
> >Content-Transfer-Encoding: 7bit
> 
> Please don't do that. This is a text only newsgroup.
> 
> >I am looking for a way to get the running total into this little sub. I
> >
> >foreach my $i (0 .. $#products) {
> 
> >  $row_total=sprintf("%4.2f", $row_total);
> 
>    $running_total += $row_total;
> 
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> Pohl's law:
>          Nothing is so good that somebody, somewhere, will not hate it.


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

Date: Sat, 11 Nov 2000 23:27:45 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: How to call sub routines from a CGI made Form
Message-Id: <slrn90rlff.gvl.tjla@thislove.dyndns.org>

I was shocked! How could Matt Perzel <thectrain@hotmail.com>
say such a terrible thing:
>I know this is more a cgi question but I am using perl so I guess it applies
>here. Anyway I am making a form parsing script, in perl, that displays the

"I know you guys are mechanics but I drove here in my car so can you
tell me the best place to buy a pair of shoes?"

>This is what I am thinking but it doesn't seem to work
>
> print "<FORM name=\"FORM1\" action=&writeData>";

ITYM print "<FORM name=\"FORM1\" action=", &writeData, ">";

assuming writeData is the name of a sub to call.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
ADHERENT

n. A follower who has not yet obtained all that he expects to get.


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

Date: Sun, 12 Nov 2000 03:52:24 GMT
From: msalerno@my-deja.com
Subject: label not found ? and trailing decimal - still new at this
Message-Id: <8ul45n$36p$1@nnrp1.deja.com>

Sorry about posting the entire script, but I didn't know where the best
place to cut would be.  Please all keep in mind that I am still very
new at this.  The issue is that I need the script to validate Ip
addresses.  I cannot get the script to recognize labels with "next".
If I change the "next" to a "goto" it will work.  But I don't want a
goto !  Also if I enter the ip address of "10.10.10.10." it accepts it,
the trailing decimal should be read as an error.  Please let me know
where I have gone wrong.

Thanks,
Matt

#!/usr/bin/perl -w
use strict;
use vars qw($comp1 $comp2);
sub ip_check {
my @ipa = split /\./, $_[0];
return "1" unless $_[0] =~ /^[\d.]+$/ and @ipa == 4;
foreach my $i ( 0..3 ) {
return "1" unless $ipa[$i] >= 0 and $ipa[$i] < 256;}
$_[0]=~s/(^|\.)0+(\d)/$1$2/g;
return $_[0];	}
# END ip_check
# Get the First IP Address
FIRST: for (1..3)
{print "Enter the First Ip Address:	";
chomp(my $ip1 = <STDIN>);
($comp1) = ip_check($ip1);
	last unless $comp1 eq 1;
	print "\nInvalid Ip Address\n";
	next;	}
# Get the Second IP Address
SECOND:
for (1..3)
{print "Enter the Second Ip Address:	";
chomp(my $ip2 = <STDIN>);
($comp2) = ip_check($ip2);
print "\n$comp1\n$comp2";
	last unless $comp2 eq 1;
	print "\nInvalid Ip Address\n";
	print "First IP Address:		$comp1\n";
#THIS NEXT LINE IS TELLING ME "LABEL NOT FOUND"
        next "IPOA"; }
for (1..3)
{last unless $comp1 =~ $comp2;
print "\nThe First and Second Addresses need to be different\n";
next IPOA1;}
#END:
print "\nEND";


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


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

Date: Sun, 12 Nov 2000 03:57:29 GMT
From: msalerno@my-deja.com
Subject: Re: label not found ? and trailing decimal - still new at this
Message-Id: <8ul4f8$3i4$1@nnrp1.deja.com>

In article <8ul45n$36p$1@nnrp1.deja.com>,
  msalerno@my-deja.com wrote:

> #THIS NEXT LINE IS TELLING ME "LABEL NOT FOUND"
>         next "IPOA"; }
> for (1..3)
> {last unless $comp1 =~ $comp2;

Sorry for the typo - it should read

next FIRST;)

My apologies,
Matt


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


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

Date: Sun, 12 Nov 2000 03:02:08 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Launching an Long-Term Process in IIS
Message-Id: <3A0E08FC.F88D28D3@rochester.rr.com>

Todd McLaughlin wrote:
> 
> I'm trying to start an .exe program from a CGI Perl script.  I've tried:
> 
>    system( 'program.exe' );
>    system ('start program.exe');
> 
> Neither of the above return until program.exe closes.  My web browser just
> sits there waiting for the page.
Well, that's what system is supposed to do for the first one.  
perldoc -f system.  For the second one, my system (Windoze 98SE)
operates as you would expect:  program.exe begins execution and the
original program continues executing, and, if what remains is quicker
than program.exe, will terminate before program.exe does.  You might
also check out the fork function.
> 
>    exec( 'program.exe' );
> 
> The above returns control to the web browser but with the error message
> that it didn't get any html code.
The exec function does not return control to the calling program. 
perldoc -f exec.  Are you printing your header after the call?  You
should always do the header first thing.
> 
> Also, the following does not work:
> 
>    system( 'c:\program files\program.exe');
You need to read up on DOS -- you need to quote spaces in file names,
something like:

     system('"c:\program files\program.exe"');

or

     system('c:\"program files"\program.exe');
> 
> Do I have to use progra~1 instead?
You could, but you're better off to properly quote it.
> 
> Thanks!
> Todd
-- 
Bob Walton


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

Date: 11 Nov 2000 23:00:58 -0500
From: kj0 <kj0@mailcity.com>
Subject: Native float translation
Message-Id: <8ul4lq$kn8$1@panix3.panix.com>





Hi!

I have a (binary) file containing double precision (32-bit) floats in
native Linux format that I need to translate to native SGI Irix
doubles.  How is this done?

Thanks in advance,

KJ



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

Date: Sun, 12 Nov 2000 01:49:51 GMT
From: metamp@my-deja.com
Subject: need some help with RE
Message-Id: <8uksvv$u1b$1@nnrp1.deja.com>

I'm trying to test the string if there are only alphanumeric
characters ,dots and dashes no other characters the RE a made up does
not work right if ($string !~/\w*\.*\-*/){did not match} else {matched}
as I know \w stands for alfanums, the * for 0 or any, and the \. should
be exactly the dot becuse of th "\" before it and the same for the dash

can anybody help me out here




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


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

Date: Sun, 12 Nov 2000 11:46:11 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: need some help with RE
Message-Id: <y3nP5.25$Rw.2058@vic.nntp.telstra.net>

<metamp@my-deja.com> wrote in message news:8uksvv$u1b$1@nnrp1.deja.com...
> I'm trying to test the string if there are only alphanumeric
> characters ,dots and dashes no other characters the RE a made up does
> not work right if ($string !~/\w*\.*\-*/){did not match} else {matched}
> as I know \w stands for alfanums, the * for 0 or any, and the \. should
> be exactly the dot becuse of th "\" before it and the same for the dash

What you have there test if there are NOT (!~)  "0 or more Alphanumerics
(including '_') FOLLOWED by ) or more '.' followed by 0 or more '-'".

It sound like you need to use a negated character class

if ($string =~ /[^\w\.-]*/){
   print "contains illegal characters\n";
}

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Sat, 11 Nov 2000 21:24:40 -0500
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: need some help with RE
Message-Id: <3A0DFF68.BE1749B8@cc.gatech.edu>

metamp@my-deja.com wrote:

> I'm trying to test the string if there are only alphanumeric
> characters ,dots and dashes no other characters the RE a made up does
> not work right if ($string !~/\w*\.*\-*/){did not match} else {matched}
> as I know \w stands for alfanums, the * for 0 or any, and the \. should
> be exactly the dot becuse of th "\" before it and the same for the dash
>
> can anybody help me out here
>

Take your pick:
$string =~ /^[\w.-]*$/;
$string !~ /[^\w.-]/;

perldoc perlre
--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Sun, 12 Nov 2000 04:36:03 GMT
From: "alan feiler" <ppdc@home.com>
Subject: PERL AND JPGS AND SHOPPING CART
Message-Id: <T6pP5.92673$hD4.22114187@news1.rdc1.mi.home.com>

I had a program originally written in Dreamweaver.
The webmaster who inserted the jpgs did it in perl5 since this is a shopping
cart.
Recently when a word which is linked to a jpg is clicked, a script default
comes up with "image not available"
Can anyone out there comeup with a fix for this problem.
The shopping cart is kind of a hybrid written thing and doesnt follow any
scripting defaults for shopping cart code.
If anyone can help please let me know.
Thanks in advance.
ALAN






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

Date: Sun, 12 Nov 2000 01:49:19 GMT
From: gbnews@arcticmail.com (gb)
Subject: Re: Perl for Win95
Message-Id: <3a0df5ea.30653269@news.lineone.net>

On Sat, 11 Nov 2000 05:28:26 GMT, mag@ionet.net (Maggert) wrote:

>On Sat, 11 Nov 2000 04:18:55 GMT, gbnews@arcticmail.com (gb) wrote:
>
>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

Very funny,you obviously haven't done it.If you tried it you'd see
there was more than one file needed and the link to one of the files
is broken.

Getting your facts right before answering is hard to do these days.

Gary 


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

Date: Sat, 11 Nov 2000 22:58:15 -0000
From: "Dave Turing" <DaveTuring@spam.co.uk>
Subject: Please Help  - Student question regarding Flock and Semop Modules?
Message-Id: <8ukjd4$j94$1@supernews.com>

I could be completely wrong  - but here goes:

Which is considered the more advanced system and why? (flock or semop)

Why ask?  - I have some reservations about a unit project specification
which determines semops to be the more advanced system for concurrent
process control in all circumstances.

If this is true why write the flock module?   (Incidentally who wrote the
flock module?)

I do not fully understand semops, but it appears that an iterative loop
"until state is achieved" is used by the semops method, as opposed to a
suspension
of the process by the operating system using constant ( 2) with flock.

"Flock" appears the more efficient system as process control is handed to
the operating system, whereby unnecessary programme cycles are suspended.

I  have successfully used "sysopen" followed by "flock" so far, and found it
capable of handling a multiplicity of processes reading and writing to the
same file. Tested on a very recent version of linux, not sure of kernel, and
perl 5.005.

My final selection of system will be used to control a multiplicity of
concurrent perl processes, are there any limitations documented or
undocumented on semops or flock I should understand ?

Could I also ask who are, or how do I check who the authors of these perl
modules
are?( Larry Wall ).  I would like to pose these questions to the authors if
possible, assuming they have time to answer!

Thanks in advance for any assistance or rational provided.

Regards
Dave

Please reply to group or e-mail me davesperl@digital-spy.co.uk








--
**********************************************************************
Information in this email is confidential and may be privileged.
It is intended for the addressee only. If you have received it in error,
please notify the sender immediately and delete it from your system.
You should not otherwise copy it, retransmit it or use or disclose its
contents to anyone.
Thank you for your co-operation.
**********************************************************************





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

Date: Sat, 11 Nov 2000 23:47:11 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FEA6C725Craznar@24.192.1.17>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in <8ujp4u$78g$1
@lublin.zrz.tu-berlin.de>:

>Christopher Burke <craznar@hotmail.com> wrote in comp.lang.perl.misc:
>>ren.maddox@tivoli.com (Ren Maddox) wrote in
>><m366lvjwx8.fsf@dhcp11-177.support.tivoli.com>: 
>>
>>>> >  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.
>>>
>>
>>No - I don't know why it doesn't work. When I tried it - it just didn't 
>>work.
>
>Look, Christopher was asking you why *you think* the code doesn't
>work, not for your explanation why it doesn't.  In other words:

Well I typed in the letters starting with p and ending with ; into my 
editor, then typed perl test.pl - and it returned the wrong answer.

>Show what you tried.  Explain what you expected it to do.  Show
>how the result doesn't meet your expectation.  Then we can start
>talking about what's going wrong.

I tried 

$hash{x} = 4;
$hash{y} = 5;
push @fulldata, \%hash;
print $hash[0]{x}.",".$hash[0]{y};

and it printed nothing except the ','.



>
>Anno


-- 
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com


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

Date: Sun, 12 Nov 2000 01:14:03 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Pushing a hash on to a stack...
Message-Id: <ant120103bbafNdQ@oakseed.demon.co.uk>

In article <8FEA6C725Craznar@24.192.1.17>, Christopher Burke
<URL:mailto:craznar@hotmail.com> wrote:
>
> I tried 
> 
> $hash{x} = 4;
> $hash{y} = 5;
> push @fulldata, \%hash;
> print $hash[0]{x}.",".$hash[0]{y};
> 
> and it printed nothing except the ','.

Had you turned warnings on (as all good Perl programmers should)
you would have seen:

Name "main::fulldata" used only once: possible typo at testprog line 5.
Use of uninitialized value at testprog line 6.
Use of uninitialized value at testprog line 6.

 ...and from that deduced the problem.

Strictly speaking you should get used to using strict too. :-)

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Sun, 12 Nov 2000 01:38:45 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FEA7688ACraznar@24.192.1.17>

james@NOSPAM.demon.co.uk (James Taylor) wrote in 
<ant120103bbafNdQ@oakseed.demon.co.uk>:

>In article <8FEA6C725Craznar@24.192.1.17>, Christopher Burke
><URL:mailto:craznar@hotmail.com> wrote:
>>
>> I tried 
>> 
>> $hash{x} = 4;
>> $hash{y} = 5;
>> push @fulldata, \%hash;
>> print $hash[0]{x}.",".$hash[0]{y};
>> 
>> and it printed nothing except the ','.
>
>Had you turned warnings on (as all good Perl programmers should)
>you would have seen:
>
>Name "main::fulldata" used only once: possible typo at testprog line 5.
>Use of uninitialized value at testprog line 6.
>Use of uninitialized value at testprog line 6.
>
>...and from that deduced the problem.
>
>Strictly speaking you should get used to using strict too. :-)
>
>> 

$hash{x} = 4;
$hash{y} = 5;
push @fulldata, \%hash; 
print $fulldata[0]{x}.",".$fulldata[0]{y};

My apologies for typing in the wrong variables.... my point is I typed the 
push line into the working code and it stopped working.


-- 
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com


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

Date: 12 Nov 2000 02:06:52 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8uktvt$87q$1@lublin.zrz.tu-berlin.de>

Christopher Burke <craznar@hotmail.com> wrote in comp.lang.perl.misc:

>$hash{x} = 4;
>$hash{y} = 5;
>push @fulldata, \%hash; 
>print $fulldata[0]{x}.",".$fulldata[0]{y};
>
>My apologies for typing in the wrong variables....

That's why it's often recommended to cut-and-paste from the actual
code.

>                                                   my point is I typed the 
>push line into the working code and it stopped working.

Ah, but the code above works perfectly well and prints "4,5" as expected.
You don't really need the named hash, though it may first help to see
what's going on.  If you use this code in a loop, however, you will
probably push another reference to the same variable on @fulldata
each time through.

You could have achieved the same effect using

  push @fulldata, { x => 4, y => 5};

pushing an anonymous (and therefore unique) hash onto the list.

Anno


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

Date: Sun, 12 Nov 2000 03:30:26 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FEA8FD8ECraznar@24.192.1.17>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in <8uktvt$87q$1
@lublin.zrz.tu-berlin.de>:

>Ah, but the code above works perfectly well and prints "4,5" as expected.
>You don't really need the named hash, though it may first help to see
>what's going on.  If you use this code in a loop, however, you will
>probably push another reference to the same variable on @fulldata
>each time through.

Even if I do %hash = undef at the start of each loop ?

>You could have achieved the same effect using
>
>  push @fulldata, { x => 4, y => 5};

Cannot - in the eventual code, the push is separated from the data entry 
and data retrieval.

>
>pushing an anonymous (and therefore unique) hash onto the list.
>
>Anno
>


-- 
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com


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

Date: Sun, 12 Nov 2000 04:28:51 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <70pP5.223$xb1.11555@eagle.america.net>

On Sun, 12 Nov 2000 03:30:26 GMT, Christopher Burke <craznar@hotmail.com> wrote:
>anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in <8uktvt$87q$1
>@lublin.zrz.tu-berlin.de>:
>
>>Ah, but the code above works perfectly well and prints "4,5" as expected.
>>You don't really need the named hash, though it may first help to see
>>what's going on.  If you use this code in a loop, however, you will
>>probably push another reference to the same variable on @fulldata
>>each time through.
>
>Even if I do %hash = undef at the start of each loop ?

That, of course, would also invalidate the previous \%hash values that
were pushed onto @fulldata.  What I think you want is a lexical
variable that you arrange to go out of scope *after* taking a
reference to it.  

>>You could have achieved the same effect using
>>
>>  push @fulldata, { x => 4, y => 5};
>
>Cannot - in the eventual code, the push is separated from the data entry 
>and data retrieval.

And this is what's caused the frustration with this thread.  

-- 
Garry Williams
Zvolve Systems, Inc.  
+1 770 551-4504


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

Date: Sun, 12 Nov 2000 00:44:00 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Random Array with Sort?
Message-Id: <ant12000006cfNdQ@oakseed.demon.co.uk>

In article <m3r94i157n.fsf@mumonkan.sunstarsys.com>, Joe Schaefer
<URL:mailto:joe+usenet@sunstarsys.com> wrote:
>
> From Abigail's documentation of Algorithm::Numeric::Shuffle,
> it should be in Knuth vol.2

Fisher is not in the index but Yates is. I've now found it
in section 3.4.2 algorithm P on page 145. Thank you.

> You can also find an implementation via
> % perldoc -q shuffle

Found it in perlfaq4, thanks.

> > Please could someone explain Fisher-Yates or point me to 
> > a suitable URL. Thanks.
> 
> Normally I'd point you at a URL, but I didn't see anything
> satisfactory. I'm not a CS major, but I'll take a shot at 
> it for you.
[snip detailed discussion]

Thank you for going to all that trouble.

> In theory, this is a decent O(n) implementation of F-Y.  
> However, in reality it's probably pretty useless 
> for serious work because of your box's implementation
> of "rand".

Actually, the RISC OS port of Perl 5.5 which I am using
has a very poor rand() in fact it is very obviously NOT
uniform. I assume that the porter either implemented his
own version badly, or used a duff library because I can't
believe that the core rand() is that bad. I have resorted
to writing a Mitchell-Moore additive generator instead
of using the built in rand(). Pity, but there you go...

> if you try to shuffle say a 7-deck 
> shoe via a single pass of F-Y as above, your 
> deck will be *very* far from random.  How far 
> from random, and how many passes might actually 
> be necessary, I leave for you to figure out.

Surely the point is that the outcome of any shuffling
algorithm is dependent on the seed alone and if this
is a 32 bit number then it can't be possible to generate
more than 2**32 different permutations. So, if the array
to be shuffled has more than 12 elements then you cannot
hope to be able to generate all permutations, let alone
generate those that you can with equal probability.

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Sun, 12 Nov 2000 02:07:44 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Re: Random Array with Sort?
Message-Id: <8uku1f$uqj$1@nnrp1.deja.com>

In article <slrn90pk1v.dck.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:
>
> >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.

When I use your sort on ('a'..'c'), I get this distribution from 100K
trials:

abc 25167
acb 12408
bac 24963
bca 12449
cab 12700
cba 12313
keys:    6

Still very biased.

However, with ('a'..'g'), it requires an inordinate number of trials to
generate all permutations. (I was still missing 50 of 5040 at 200K).

> 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.
>

Changing to sort { rand( 10000 ) - 5000 } does not change the
distribution of ('a'..'c'). Furthermore, the distribution using sort { -
rand( 2 ) } is not significantly different. (Using "int" seems to make
no difference at all.)

> >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.
>

I timed it on Sun Ultra at work the other day, and sort was faster. I'll
have to try it on some other systems too...

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


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


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

Date: Sun, 12 Nov 2000 02:53:59 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Random Array with Sort?
Message-Id: <slrn90s1i4.kh5.tjla@thislove.dyndns.org>

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

>When I use your sort on ('a'..'c'), I get this distribution from 100K
>trials:

>Still very biased.

Yeah. I think the 'sort' method is just wrong. Did you try the F/Y
method on 'a'..'c'? When I did the results seemed very non-biased.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
BIGOT

n. One who is obstinately and zealously attached to an opinion that
you do not entertain.


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

Date: 11 Nov 2000 23:09:52 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Self-modifying code in Perl
Message-Id: <8ukjk0$l0k$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 <slrn90ricj.gs3.mgjv@martien.heliotrope.home>:
> > And about ISO C: who cares?  There are many systems where half of ISO
> 
> I care. And the people on clc. You brought up the point that C is much
> less portable than Perl, and I just remarked that I sincerely doubt
> that, since ISO C compilers are available for many more platforms than
> Perl interpreters.

I still do not understand your claim.  Do you say that there are
systems with ISO C where Perl will not build given proper config.h?

> > C library would not make any sense.  It would not help being ISO: the
> > C compiler will not support ISO.
> 
> There are many platforms where part of the Perl builtins don't make
> sense (getpw*, flock, msg* sem*, getgr*), because they are direct
> translations of system calls that are specific to one group of OS. 

These operators make sense on any platform.

  croak("%s() not implemented", "flock");

Ilya


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

Date: Sun, 12 Nov 2000 14:28:41 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Self-modifying code in Perl
Message-Id: <slrn90s3j9.gs3.mgjv@martien.heliotrope.home>

On 11 Nov 2000 23:09:52 GMT,
	Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was NOT sent to Martien Verbruggen
><mgjv@tradingpost.com.au>],
> who wrote in article <slrn90ricj.gs3.mgjv@martien.heliotrope.home>:
>> > And about ISO C: who cares?  There are many systems where half of ISO
>> 
>> I care. And the people on clc. You brought up the point that C is much
>> less portable than Perl, and I just remarked that I sincerely doubt
>> that, since ISO C compilers are available for many more platforms than
>> Perl interpreters.
> 
> I still do not understand your claim.  Do you say that there are
> systems with ISO C where Perl will not build given proper config.h?

Euhm, no.

This started as a reaction to your claim, upthread:

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

To which I responded that I don't believe that. Anyway, you can reread
what was said yourself. 

Perl needs a lot more than ISO C, and man of perl's builtin functions
only make sense on Unix systems.

But this is going nowhere.

>> > C library would not make any sense.  It would not help being ISO: the
>> > C compiler will not support ISO.
>> 
>> There are many platforms where part of the Perl builtins don't make
>> sense (getpw*, flock, msg* sem*, getgr*), because they are direct
>> translations of system calls that are specific to one group of OS. 
> 
> These operators make sense on any platform.
> 
>   croak("%s() not implemented", "flock");

Then all C libraries make sense on all platforms.

fprintf(stderr, "%s not implemented\n", f_name);
exit(EXIT_FAILURE);

That's a cop-out, Ilya.

Martien
-- 
Martien Verbruggen              | Since light travels faster than
Interactive Media Division      | sound, isn't that why some people
Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
NSW, Australia                  | speak?


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

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


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