[17454] in Perl-Users-Digest
Perl-Users Digest, Issue: 4874 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 12 18:05:29 2000
Date: Sun, 12 Nov 2000 15: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: <974070308-v9-i4874@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 12 Nov 2000 Volume: 9 Number: 4874
Today's topics:
Re: A surprise with vec() (Ilya Zakharevich)
Re: Handling Postcode Ranges <peter.sundstrom@eds.com>
Re: Handling Postcode Ranges <peter.sundstrom@eds.com>
Re: Help about sending over 1000 mails error!! (Logan Shaw)
HELP!! MIME attached file <leslies@santaland.com>
installing perl - help <maqo-nospam@netzero.net>
Re: installing perl - help <soeder@ai-lab.fh-furtwangen.de>
Re: installing perl - help (Garry Williams)
Re: need some help with RE <kiki@abc.ro>
Re: Net::Telnet & Net::Ping (Martien Verbruggen)
New to perl - Problems with Labels ! Please Help. msalerno@my-deja.com
Re: New to perl - Problems with Labels ! Please Help. <friedman@math.utexas.edu>
Re: Performance/scaleablility question: Perl/CGI vs. J (Logan Shaw)
Re: Perl style and module searches (David Combs)
Re: Perl syntax and beyond (was: Re: Perl style and mod (David Combs)
Re: Perl syntax and beyond (was: Re: Perl style and mod (David Combs)
Re: Perl syntax and beyond (was: Re: Perl style and mod (Ilya Zakharevich)
Re: Pushing a hash on to a stack... (Martien Verbruggen)
Re: Random Array with Sort? <quantum_mechanic@my-deja.com>
Re: Random Array with Sort? <joe+usenet@sunstarsys.com>
Re: Random Array with Sort? <quantum_mechanic@my-deja.com>
Re: Self-modifying code in Perl (Ilya Zakharevich)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Nov 2000 20:42:25 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: A surprise with vec()
Message-Id: <8umvbh$t5u$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Gwyn Judd
<tjla@guvfybir.qlaqaf.bet>],
who wrote in article <slrn90t3sv.pt9.tjla@thislove.dyndns.org>:
> I get that too (linuxppc with 5.6). Looks like a bug to me.
Hint: which bits are set in $x after $x = 0?
Ilya
------------------------------
Date: Mon, 13 Nov 2000 10:20:00 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Handling Postcode Ranges
Message-Id: <8un1nr$s7u$1@hermes.nz.eds.com>
Ian Boreham <ianb@ot.com.au> wrote in message
news:3A0B6D16.4EDC91C4@ot.com.au...
> Peter Sundstrom wrote:
>
> > Ian Boreham <ianb@ot.com.au> wrote in message
> > news:3A0B2423.869B85AD@ot.com.au...
> > > Peter Sundstrom wrote:
> > >
> > > > The postcodes will range from 0 to 9999. I was thinking about
> > initialising
> > > > a hash for the entire range, but it seems overkill to initialise
10,000
> > > > values.
> > >
> > > Why a hash an not just a good old-fashioned array? Lookup should be
faster
> > and
> > > it should be more space-efficient, if you are populating the entire
range.
> >
> > I'm unsure how you would implement it as an array lookup.
>
> Perhaps I misunderstood you. I thought you were suggesting using
individual
> postcodes as keys in the hash, and adding an entry for each, to give you
the
> lookup facility. E.g. $range = $postcoderange{'1234'};
>
> I was suggesting that if you were to do this for each postcode (which you
were
> saying seemed like overkill), that rather than populating 10000 hash
entries,
> you should use a 10000-entry array. Lookup would just use the (decimal,
even
> for 0200-style codes) numerical value of the postcode as an array index.
E.g.
> $range = $postcoderange[1234];
>
> This is not that different from the hash idea (although slightly better, I
> think) in terms of storage required and access speed, but I was just
wondering
> why you suggested a hash instead of an array? Did I completely miss the
point?
I think I couldn't see the wood for the trees. You have understood me
correctly and for some reason I thought that implementing an array would
require quite different coding. I'm not sure why I got that idea. I'll
benchmark the hash and array methods to see which one is quicker.
------------------------------
Date: Mon, 13 Nov 2000 10:24:13 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Handling Postcode Ranges
Message-Id: <8un1vp$sq1$1@hermes.nz.eds.com>
Wolfgang Hielscher <W.Hielscher@mssys.com> wrote in message
news:3A0BCADA.331AD33A@mssys.com...
> Peter Sundstrom wrote:
> > So are you are saying that the cost of setting up a hash would be fairly
> > minimal compared to any other method?
>
> No, the costs for setting up a hash, or even better an array as Ian
> Boreham pointed out (forget the hash-idea), wouldn't be "minimal"
> compared to for example setting up the "@upper_bound" array in the code
> I posted.
>
> But the choice of method/implementation for determing your range-id must
> be made based upon the characteristics of your problem:
>
> - you want to save memory in the first place
> Well, IMO the @upper_bound array may be one way...
>
> - you want a fast programm and need to reconfigure your postcode ranges
> fairly often
> Given a postcode configuration, you do just, let's say 20 lookups and
> then change the configuration. Then the price (in terms of execution
> time) for setting up a 10,000 element array seems too high compared to
> the time you save by fast lookups.
>
> - you need to reconfigure your ranges not so often
> Let's say you do 200,000 lookups. The fixed setup-costs (time you
> spend once) for your 10,000 element array may just become irrelevant
> compared to the time you save 200,000 times by fast array-lookups.
Your last example is more the environment I will be running. Memory is only
a minor concern as the server has plenty of memory (2Gb) and swap.
Looks like an array is the way to go.
------------------------------
Date: 12 Nov 2000 16:02:58 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Help about sending over 1000 mails error!!
Message-Id: <8un42i$70l$1@boomer.cs.utexas.edu>
In article <t0tnfbh8r27hdf@corp.supernews.com>,
Arthur Dalessandro <adalessandro@odione.com> wrote:
>Sounds like an O/S problem, more specifically a unix problem.
Sounds more like a file descriptor leak to me.
Also, sounds like the original poster is trying to invoke
/usr/lib/sendmail 1000 times, which is really not necessary since you
can open up an SMTP session (using Net::SMTP) and send several
(hundreds of) messages over that same session.
Or, I believe Mail::Internet objects have a smtpsend() method.
Another option is to look at Mail::BulkMail.
Yet another possibility is that the original poster doesn't want to
send a zillion separate mail messages, but instead wants to send a
single mail message to a zillion users. This will be more efficient
anyway, especially if there are recipients who receive mail on the same
server, since only one copy must be sent instead of several. In that
case, the easiest method is to construct a message (with whatever
headers you like), open up a Net::SMTP session, and then specify a
zillion addresses when calling the recipient() method.
Of course, info on all these modules can be found at
http://search.cpan.org/ .
- Logan
------------------------------
Date: Sun, 12 Nov 2000 20:14:45 GMT
From: "leslie" <leslies@santaland.com>
Subject: HELP!! MIME attached file
Message-Id: <VSCP5.28532$25.5971678@news1.rdc1.ne.home.com>
I have figured out how to send a file using sendmail and MIME format. But
for some reason whenever you receive the mail that it sends out.. the file
is just empty.. nothing there.. basically the only thing that goes through
is that there is an attached file and the name of the attached file but the
contents of the file dont seem to go through.. Here is a copy of the code i
am using .. someone please help.
$SENDMAIL = '/usr/lib/sendmail/';
open(MAIL,"|$SENDMAIL -t") || die "Can't open mail!\n";
print MAIL "To: g0d_online\@yahoo.com, leslies\@santaland.com,
bastage\@aol.com\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: multipart/mixed;\n";
print MAIL " boundary=\"next_part_of_message\"\n\n";
print MAIL "This is a multipart message in MIME format\n";
print MAIL "\n--next_part_of_message\n";
print MAIL "Content-Type: text/plain\n\n";
print MAIL "$FORM{'message'}\n";
print MAIL "\n--next_part_of_message\n";
print MAIL "Content-Type: application/octet-stream\n";
print MAIL " name=\"$FORM{'XX-attach_file_name'}\"\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: attachment;\n";
print MAIL "
filename=\"$FORM{'XX-attach_file_name'}\"\n\n";
open (TEXT, "uuencode $FORM{'XX-file_attached'}|");
while (<TEXT>) {
chop $_;
print MAIL $_,"\n";
}
close TEXT;
print MAIL "\n--next_part_of_message--\n";
close (MAIL);
------------------------------
Date: Sun, 12 Nov 2000 21:21:11 GMT
From: "Maqo" <maqo-nospam@netzero.net>
Subject: installing perl - help
Message-Id: <bRDP5.133263$ib7.17949325@news1.rdc1.nj.home.com>
I'm currently running Mandrake 7.1 and installed all the included perl
modules, but I can't seem to get even the simplest program to work. Even:
#!/usr/bin/perl
print "Hello, world!\n"
fails to produce any output when executed. Am I possibly missing something?
I'd really appreciate any help. Thanks in advance!
------------------------------
Date: Sun, 12 Nov 2000 22:55:12 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: Re: installing perl - help
Message-Id: <3A0F11C0.CDE75EF1@ai-lab.fh-furtwangen.de>
Maqo wrote:
> =
> I'm currently running Mandrake 7.1 and installed all the included perl
> modules, but I can't seem to get even the simplest program to work. Ev=
en:
> =
> #!/usr/bin/perl
> print "Hello, world!\n"
> =
> fails to produce any output when executed. Am I possibly missing somet=
hing?
> I'd really appreciate any help. Thanks in advance!
Did you check your install directory?
Perhaps /usr/local/bin/perl?
Oliver S=F6der
------------------------------
Date: Sun, 12 Nov 2000 22:31:35 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: installing perl - help
Message-Id: <bTEP5.269$xb1.15306@eagle.america.net>
On Sun, 12 Nov 2000 22:55:12 +0100, Oliver Söder
<soeder@ai-lab.fh-furtwangen.de> wrote:
>Maqo wrote:
>>
>> I'm currently running Mandrake 7.1 and installed all the included
>> perl modules, but I can't seem to get even the simplest program to
>> work. Even:
>>
>> #!/usr/bin/perl
>> print "Hello, world!\n"
>>
>> fails to produce any output when executed. Am I possibly missing
>> something? I'd really appreciate any help. Thanks in advance!
>
>Did you check your install directory?
>
>Perhaps /usr/local/bin/perl?
The original poster didn't give enough information. For example,
$ cat x
#!/usr/no_such_directory/bin/perl -w
print "Hello world\n"
$ chmod +x x
$ perl x
Hello world
$ ./x
ksh: ./x: not found
$ /usr/no_such_directory/bin/perl x
ksh: /usr/no_such_directory/bin/perl: not found
$ perl no_such_file
Can't open perl script "no_such_file": No such file or directory
$
Notice that none of these cases results in "fails to produce any
output when executed."
The only scenario that I can think of to match the original poster's
reported symptom is the following:
$ touch perl
$ chmod +x perl
$ ./perl x
$
In other words, the perl in the original poster's path is an empty,
executable file.
--
Garry Williams
------------------------------
Date: Mon, 13 Nov 2000 00:17:58 +0200
From: Rolf <kiki@abc.ro>
Subject: Re: need some help with RE
Message-Id: <3A0F1716.DD1B283A@abc.ro>
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
the problem with your regular expression is that every bit of it is
optional
let's see:
\w* = zero or more word characters followed by
\.* = zero or more dots folowed by
\- = zero or more dashes
no part of this regex MUST match
when the regex engine tries to match this regex, it tries to match the \w*
part first
but if the string doesn't start with an a word character, it doesn't fail,
it just goes to the next part,
\.* which will also not fail (it's optional because of the *) and then to
\-, which will also not fail
so the engine will match any word characters, dots and dashes (btw, in
that order only) but it will succeed in every case.
you better read up on regexes (i suggest 'Mastering Regular Expressions'
from O'Reilly)
finally what you probably want is
if ($string !~ m/^(\w|\.|\-)*$/) {...} else {...}
note that this regex will succeed if the string is empty ($string eq "").
if you don't want it to do so
change the '*' to a '+' (this will force the regex to fail if the string's
empty)...
kiki
------------------------------
Date: Sun, 12 Nov 2000 22:32:33 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Net::Telnet & Net::Ping
Message-Id: <slrn90u6k5.7ck.mgjv@verbruggen.comdyn.com.au>
On Thu, 09 Nov 2000 19:00:44 GMT,
nodo70@my-deja.com <nodo70@my-deja.com> wrote:
> Thanks for your quick response Martien.
>
>>
>> And I changed it to do udp pings, because I didn't feel like becoming
>> root to test this.
>>
> What do you mean by saying above? UDP PING? Excuse myself if I am
> just being idiot here.
I actually followed up to this, at home, but with my gateway dying,
and the version of leafnode I'm running being buggy, it must've got
lost.
Anyway, the Net::Ping documentation talks about the differences
between a real ping and a UDP echo. The main reason that there is a
difference is that ICMP requires one to open a socket in raw mode, and
build a packet yourself. On many systems only privileged users can do
this, and on some systems (Win32) raw sockets aren't even implemented
in the stack (ICMP packets get built by code in ICMP.DLL there)
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is the answer, but only if you
Commercial Dynamics Pty. Ltd. | phrase the question very carefully
NSW, Australia |
------------------------------
Date: Sun, 12 Nov 2000 22:11:56 GMT
From: msalerno@my-deja.com
Subject: New to perl - Problems with Labels ! Please Help.
Message-Id: <8un4j9$gj1$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 IS THE LINE THAT I AM HAVING PROBLEMS WITH !
next "FIRST"; }
for (1..3)
{last unless $comp1 =~ $comp2;
print "\nThe First and Second Addresses need to be different\n";
next FIRST;}
END:
print "\nEND";
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 12 Nov 2000 16:37:17 -0600
From: Chas Friedman <friedman@math.utexas.edu>
Subject: Re: New to perl - Problems with Labels ! Please Help.
Message-Id: <3A0F1B9D.16DEBE0F@math.utexas.edu>
Why do you have FIRST in quotes? Next can be followed by a label, but I
think this shouldn't be in quotes.
On the other hand, goto can be followed by an expression (which can be a
string.)
chas friedman
msalerno@my-deja.com wrote:
...
> #THIS IS THE LINE THAT I AM HAVING PROBLEMS WITH !
> next "FIRST"; }
...
------------------------------
Date: 12 Nov 2000 15:41:41 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Performance/scaleablility question: Perl/CGI vs. Java Servlets?
Message-Id: <8un2ql$6uv$1@boomer.cs.utexas.edu>
In article <m1g0kxs843.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>Summary: Perl is used for LARGE REAL-WORLD MISSION-CRITICAL apps.
>It's not a toy. It's the real thing.
Nah, it's both a toy and the real thing. In my mind at least. Which
is what makes it good (the fact that it's both, not my mind).
- Logan
------------------------------
Date: 12 Nov 2000 21:33:37 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Perl style and module searches
Message-Id: <8un2bh$q1$3@news.panix.com>
In article <3a02e17a@cs.colorado.edu>,
Tom Christiansen <tchrist@perl.com> wrote:
>In article <EcBM5.13452$AM5.253150@news1.nokia.com>,
>Elaine Ashton <elaine@chaos.wustl.edu> wrote:
>>news:3A021193.6761027B@hotmail.com...
>>> http://perldoc.cpan.org, recommended by Elaine Ashton, seems to give me
>>more
>>> useful search results than http://search.cpan.org. At least on first
>>> test. Perldoc.com also looks quite interesting.
>>
>>Each of the different search engines have their own strengths.
>
>But they all have the same weakness: they're flipping web crud.
>This is onerous at best.
>
>My new stuff does not suffer from this silliness, and is much more
>featureful besides. However, it does not look for other people's
>stuff on other systems, only documentation that comes from the
>standard distribution or optional (perhaps CPAN) modules you've
>installed.
>
>--tom
For those of us with fast-expiring news-sources (eg panix.com),
could you please repost your "new stuff"?
So that n different people don't each have to
go search through deja.
THANKS!
David
------------------------------
Date: 12 Nov 2000 21:28:21 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Perl syntax and beyond (was: Re: Perl style and module searches)
Message-Id: <8un21l$q1$1@news.panix.com>
In article <rp080tcuiumc6qc62rmnfvr2vff124ogr2@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>Gwyn Judd wrote:
>
>>>So in what way does splice() on an array (of scalars or references to
>>>more complex objects) not perform the function you want?
>>
>>Well addition or deletion in a linked list is O(1) whereas splice is
>>O(n).
>
>Is it? I thought accessing an element in a linked list is O(n) (while
>for arrays, it's O(1)) Therefore, if you need to locate an item in a
>linked list first before deleting it, or inserting something right after
>it, that must be O(n), too. (Inless there is some hashy structure, or a
>binary tree, or such, pointing inside the tree. That's O(log n), at
>best, I guess.)
Re linked-lists, true iff you start at the BEGINNING of the list.
But that's not what you usually do when you have chosen that
form of data structure (unless it is short) -- usually you are
ALREADY traversing through it, and at some point you decide
"I need to insert something here" (or delete this current node),
and for THAT, it's O(1).
Whereas, for an array, whether via splice or any other means,
doing that means you have to slide the entire remaining items
either left or right, ie O(n).
No big deal UNLESS (a) you are doing it within a loop (ie,
LOTS of slides, ie O(n-squared), or "n" is big (and, again,
doing it more than once).
Is also similar problem with "shift" (which is fast)
opposite, push-onto-beginning, eg when trying to do a
"queue" (eg for breadth-first-search). Adding one
to the first shifts whole rest of it to the right, ie
must copy entire array. Do that a bunch of times and
it becomes O(n-squared).
There is some hack with push that you can do, via
allocating more room when initializing it -- but that
is for growing ONLY to the RIGHT.
Only way to do queue that way is to build your own,
I have been told, OO, where YOU manage the storage.
>
>Anyway, this distinction between arrays and linked lists is too low
>level for me. I have no complaints about Perl's speed, so I only
>concentrate on the syntax.
Well, n-squared can get pretty time-consuming, fast.
David
------------------------------
Date: 12 Nov 2000 21:30:47 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Perl syntax and beyond (was: Re: Perl style and module searches)
Message-Id: <8un267$q1$2@news.panix.com>
In article <8u4pkr$1ss$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Abigail
><abigail@foad.org>],
>who wrote in article <slrn90bm48.f32.abigail@tsathoggua.rlyeh.net>:
>> There are cases where linked lists are faster than arrays. But more
>> often in C than in Perl.
>
>And the principal reason for this rarity may be that it is so damn
>hard to implement doubly-linked lists in Perl... Another reason is
>that Perl so damn slow, that the difference between O(n^2) and O(n)
>algorithms is not noticable until you finish testing and start
>real-life applications...
>
>Ilya
How about you two (Ilya and the guy with the syntax to
suggest) give your suggestions and (especially) reasons
to the perl6 people?
David
------------------------------
Date: 12 Nov 2000 22:57:27 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl syntax and beyond (was: Re: Perl style and module searches)
Message-Id: <8un78n$2c0$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to David Combs
<dkcombs@panix.com>],
who wrote in article <8un267$q1$2@news.panix.com>:
> How about you two (Ilya and the guy with the syntax to
> suggest) give your suggestions and (especially) reasons
> to the perl6 people?
Hmm? Did you take this perl6 joke seriously?!
And I already killed at least 50% of the problem by the weak
references. Another 50% does not look "easily" manageable outside of
the user space... Basically, one needs to duplicate the refcounts
infrastructure in the user space.
Here is how a "graph" object may look like:
0) There is one special "umbrella" hash with keys being the
stringified vertices of the graph;
a) A vertex is a hash with keys being the stringified neighbors of
the vertex, and values the neighbors themselves;
b) The values of the "umbrella" hash are of the form [refcount,
vertex], here vertex is a weak (or a strong) reference, and the
refcount is the number of vertices which keep it as a neighbor;
c) There may be an additional key in "a" leading from a vertex hash
to the umbrella hash.
To create an empty graph: $umbrella = {};
To add a vertex without neighbors: $vertex->{_} = $umbrella;
$umbrella->{$vertex} = [0, $vertex];
To remove a not-a-neighbor vertex: delete $vertex->{_}{$vertex};
Is a vertex not-a-neighbor? ... unless $vertex->{_}{$vertex}[0];
To add an edge from $v1 to $v2: $v1->{$v2} = $v2;
++$v2->{_}{$v2}[0];
To remove an edge from $v1 to $v2: delete $v1->{$v2};
$v2->remove if $v2->not_a_neighbor;
$umbrella->DESTROY: $_->[1]->remove_all_edges
for keys %$umbrella;
# Won't work? modifies %$umbrella...
$_->[1]->remove for keys %$umbrella;
Looks very dirty, but I have no idea how to incorporate such a logic
into a reusable low-level stuff with a simple interface - a stuff
which would deserve inclusion into the core...
Ilya
------------------------------
Date: Sun, 12 Nov 2000 22:05:56 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <slrn90u529.7ck.mgjv@verbruggen.comdyn.com.au>
On 12 Nov 2000 11:19:37 -0600,
Ren Maddox <ren.maddox@tivoli.com> wrote:
> craznar@hotmail.com (Christopher Burke) writes:
>
>> mgjv@tradingpost.com.au (Martien Verbruggen) wrote in
>> <slrn90sihq.gs3.mgjv@martien.heliotrope.home>:
>>
>> >Can we no assume that the question has been answered?
>> >
>>
>> My decades of programming have obviously left the wrong meaning of
>> reference imprinted ... so I have no idea what the perl world actually
>> means by a reference. I'll just plod along with what I have.
>
> Perhaps you could clarify exactly what meaning of reference your
> decades of programming have left you with?
I don't think you'll get a decent answer to that. None of the
straight-forward questions to the OP in this thread have been
answered.
>> I think we can assume that as someone not quite experienced enough with
>> PERL that I will not get my question answered.
To the OP:
You said you were not a troll, right?
> Well, I suppose that depends on your question:
>
> If your question is/was, "Can I enable the syntax $array[0]{x} to work
> without using references?", then the answer is, "No, you cannot, that
> uses references."
>
> If your question is/was, "Can I use push to populate an array such
> that the syntax $array[0]{x} works, without taking a reference to an
> existing structure (i.e. \%hash)?", then the answer is "Yes, you just
> need to use anonymous structures (i.e. { %hash })."
Or write a sub with a prototype, and hide the fact that it is a
reference int he code where you do the push. But it is, as you say,
still a reference.
The only solution I could come up with that doesn't use a reference
uses multidimensional hashes, in the old sense of the word. The OP
hasn't even bothered to say whether that was something they could live
with.
> If your question is/was neither of these, then you'll probably need to
> restate it to get an answer.
I doubt you'll get a sensible answer.
> It is most certainly not true that people here don't want to answer
> your question. I am certainly trying to do so and I know that others
> are as well.
I would say that the length of this thread, and the number of people
participating in it, has made it very clear that the willingness to
help is definitely there.
I now officially declare the OP a troll. As far as I am concerned,
neither this thread, nor the OP exist anymore.
Martien
--
Martien Verbruggen |
Interactive Media Division | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Sun, 12 Nov 2000 20:33:14 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Re: Random Array with Sort?
Message-Id: <8umuqb$c48$1@nnrp1.deja.com>
In article <ant12000006cfNdQ@oakseed.demon.co.uk>,
James Taylor <james@NOSPAM.demon.co.uk> wrote:
>
> 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.
Umm, gee, doesn't this depend on how many random numbers are required
for each call to shuffle, and what the cycle of the random number
generator is?
What is the period of shuffle given the same input?
What is the smallest K such that shuffle(N) = shuffle(N+K) implies that
shuffle(N+1) = shuffle(N+K+1)? (This is not the same as simply
requiring the smallest K such that shuffle(N) = shuffle(N+K) ).
Since the result of shuffle depends on the sequence of numbers returned
from rand, we don't have to throw up our hands when we have more than
12 cards.
Given all of that, it is not difficult (e.g., Knuth) to have a random
number generator with period much longer than than the number of bits
employed. With a little more work, almost all of the possible
permutations of the 2**32 numbers could be generated, which approaches
(2**32)! [factorial].
-QM
--
Quantum Mechanics: The dreams stuff is made of.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 12 Nov 2000 16:18:13 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Array with Sort?
Message-Id: <m3vgtssxd6.fsf@mumonkan.sunstarsys.com>
Quantum Mechanic <quantum_mechanic@my-deja.com> writes:
> Since the result of shuffle depends on the sequence of numbers returned
> from rand, we don't have to throw up our hands when we have more than
> 12 cards.
>
> Given all of that, it is not difficult (e.g., Knuth) to have a random
> number generator with period much longer than than the number of bits
> employed. With a little more work, almost all of the possible
> permutations of the 2**32 numbers could be generated, which approaches
> (2**32)! [factorial].
Right, but the question is, can you implement a decent F-Y by reseeding the
stock linear congruence rand?
I benchmarked the following subroutines and they all seem to perform within
5% of each other on my box. I have no idea how much more "random" one is
from another, but it might be worth trying to find out ;)
#!/usr/bin/perl -w
use Benchmark;
my $bits = 8;
my $size = 1<<$bits;
my @mix = (0..$size-1);
my @deck = (1..$size);
sub FAQ_shuffle (@) {
my $i;
for ($i = @_; --$i; ) {
my $j = int rand ($i+1);
next if $i == $j;
@_[$i,$j] = @_[$j,$i];
}
}
sub shuffle (@) {
my $i = @_;
while ($i>0) {
my $j = int rand($i--);
$_ = $mix[$i];
@_[$_,$j] = @_[$j,$_];
}
}
sub reseed {
shuffle(@mix);
srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
warn "reseed";
}
#########################
sub faq_shuf () {
return sub { FAQ_shuffle(@deck); wantarray ? @deck : \@deck };
}
sub shuf () {
return sub { shuffle(@deck); wantarray ? @deck : \@deck };
}
sub my_shuffle () {
my $n = 1 << (($_ = 16 - $bits) > 4 ? $_ : 4) ;
warn "N=$n";
return sub {
reseed() unless int rand $n;
shuffle(@deck);
wantarray ? @deck : \@deck;
};
}
#########################
timethese (-30, {
FAQ => faq_shuf(),
SHUFFLE => shuf(),
MY => my_shuffle(),
});
__END__
YMMV!
--
Joe Schaefer
------------------------------
Date: Sun, 12 Nov 2000 22:10:49 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Re: Random Array with Sort?
Message-Id: <8un4h5$gik$1@nnrp1.deja.com>
In article <m3vgtssxd6.fsf@mumonkan.sunstarsys.com>,
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> Quantum Mechanic <quantum_mechanic@my-deja.com> writes:
>
> > Since the result of shuffle depends on the sequence of numbers
returned
> > from rand, we don't have to throw up our hands when we have more
than
> > 12 cards.
> >
> > Given all of that, it is not difficult (e.g., Knuth) to have a
random
> > number generator with period much longer than than the number of
bits
> > employed. With a little more work, almost all of the possible
> > permutations of the 2**32 numbers could be generated, which
approaches
> > (2**32)! [factorial].
>
> Right, but the question is, can you implement a decent F-Y by
reseeding the
> stock linear congruence rand?
Why do you need to reseed it? Until you have checked the distribution of
permutations for uniformity, you shouldn't be asking how to make it
better.
>
> I benchmarked the following subroutines and they all seem to perform
within
> 5% of each other on my box. I have no idea how much more "random" one
is
> from another, but it might be worth trying to find out ;)
[snip]
So find out! If there are K permutations and T trials, the average
permutation's frequency will be T/K. If all permutations are equally
likely, then the standard deviation (from this average) will be small
compared to T/K. The "range" (max-min) across all permutation
frequencies will also be "small" in some sense. A figure of merit might
be STDDEV*RANGE. (I'm not sure if this is a good choice.)
With this is mind, conduct many "runs of trials", and average this
figure of merit over all runs. By the central limit theorem, each
algorithms' FOM will tend to a limiting value. The algorithm with the
best FOM wins.
[changing gears]
The original question asked whether "sort" would be useful for
shuffling, since it appeared that it ran faster (at least on some small
arrays). This in spite of the fact that F/Y is O(n), while sort is
O(n*log(n)). Perhaps this is because sort is implemented in C, but F/Y
was implemented in Perl. [Yes, I know, if I really want F/Y to be
faster, write it in C.]
-QM
--
Quantum Mechanics: The dreams stuff is made of.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 12 Nov 2000 20:39:48 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Self-modifying code in Perl
Message-Id: <8umv6k$t4m$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 <slrn90sqph.gs3.mgjv@martien.heliotrope.home>:
> The fact that a large number of them don't work on certain platforms,
> and some of them never will work there, doesn't mean that we should just
> ignore them, and disregard everything that is inconvenient to port as
> 'not a requirement for a perl port'.
Nothing is a requirement for Perl port. If files are not supported on
the given platform, there is no need to have any file operation.
> Why was so much work done to make fork() work on Win32 platforms
This always puzzled me. fork() would work out-of-the-box with a
decent (and tiny) CRT, such as RSX. It would not be very efficient,
but so is not the current solution (IIRC).
> Writing fully portable code is impossible in Perl, as soon as you hit
> one of those legacy functions. Even if you use paths, you run that risk.
> Even if you read text files, or need to relate their size to internal
> representations, you are unportable (which is where this started).
> Writing portable code is hard. People have full-time jobs porting code
> to various platforms.
>
> Why the denial about this? it's not as if it's bad or something. It's
> just a fact of life. Accept it, and continue to use it.
What this has to do with the fact that Perl is more portable than ISO C?
> > croak() does not make your program die.
> unless you catch the exception raised by die, your program is gone.
Yes, and a portable program will catch it and will choose some other
code path.
Ilya
------------------------------
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 4874
**************************************