[19605] in Perl-Users-Digest
Perl-Users Digest, Issue: 1800 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 24 03:10:31 2001
Date: Mon, 24 Sep 2001 00:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1001315413-v10-i1800@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 24 Sep 2001 Volume: 10 Number: 1800
Today's topics:
Simple Hash and Random Problem (BUCK NAKED1)
Re: Simple Hash and Random Problem <wyzelli@yahoo.com>
Re: Simple Hash and Random Problem <davidhilseenews@yahoo.com>
Re: sub key index sorting <dtweed@acm.org>
Re: This has got to be a bug (David Combs)
Re: This has got to be a bug (Martien Verbruggen)
Re: using Inline.pm to distribute binary perl modules (Soren Andersen)
Using URLs as hash keys <nobody@nowhere.com>
Re: Using URLs as hash keys <Laocoon@eudoramail.com>
Re: Using URLs as hash keys (Martien Verbruggen)
Re: Using URLs as hash keys <nobody@nowhere.com>
Re: Why are tabs converted to spaces? <pwasson@mindspring.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 23 Sep 2001 23:39:30 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Simple Hash and Random Problem
Message-Id: <26465-3BAEB902-93@storefull-244.iap.bryant.webtv.net>
Why does the *value* of "3" never print in this script I wrote?
#!/usr/bin/perl -wd
use CGI::Carp qw(fatalsToBrowser);
use strict;
my %text = (1, "<font color='blue' size='1'>Random Text 1</font>",
2, "<font color='red' size='2'>Random Text 2</font>",
3, "<font color='006600' size='4'><strong>Rand 3</strong></font>");
my $rand = int(rand(values(%text)));
my $random_text = $text{$rand};
print "Content-type: text/html\n\n";
print <<EOL;
<HTML>
<HEAD>
<TITLE>Random Text Assoc Array</TITLE>
</HEAD>
<BODY>
$random_text<BR>
</BODY>
</HTML>
EOL
the Best to All!
--Dennis
------------------------------
Date: Mon, 24 Sep 2001 15:02:13 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Simple Hash and Random Problem
Message-Id: <Xrzr7.37$kM3.648@wa.nnrp.telstra.net>
"BUCK NAKED1" <dennis100@webtv.net> wrote in message
news:26465-3BAEB902-93@storefull-244.iap.bryant.webtv.net...
> Why does the *value* of "3" never print in this script I wrote?
>
> #!/usr/bin/perl -wd
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
>
> my %text = (1, "<font color='blue' size='1'>Random Text 1</font>",
> 2, "<font color='red' size='2'>Random Text 2</font>",
> 3, "<font color='006600' size='4'><strong>Rand 3</strong></font>");
>
>
> my $rand = int(rand(values(%text)));
Because the value of $rand will be in the range 0 .. 2, not 1 .. 3. Add one
to it to get the range you desire. (int 0.9 = 0).
> my $random_text = $text{$rand};
> print "Content-type: text/html\n\n";
> print <<EOL;
> <HTML>
> <HEAD>
> <TITLE>Random Text Assoc Array</TITLE>
> </HEAD>
> <BODY>
> $random_text<BR>
> </BODY>
> </HTML>
> EOL
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Mon, 24 Sep 2001 05:25:25 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: Simple Hash and Random Problem
Message-Id: <9tzr7.14368$n_2.2554260@news1.rdc1.md.home.com>
"BUCK NAKED1" <dennis100@webtv.net> wrote in message
news:26465-3BAEB902-93@storefull-244.iap.bryant.webtv.net...
> Why does the *value* of "3" never print in this script I wrote?
>
> #!/usr/bin/perl -wd
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
>
> my %text = (1, "<font color='blue' size='1'>Random Text 1</font>",
> 2, "<font color='red' size='2'>Random Text 2</font>",
> 3, "<font color='006600' size='4'><strong>Rand 3</strong></font>");
>
>
> my $rand = int(rand(values(%text)));
> my $random_text = $text{$rand};
> print "Content-type: text/html\n\n";
> print <<EOL;
> <HTML>
> <HEAD>
> <TITLE>Random Text Assoc Array</TITLE>
> </HEAD>
> <BODY>
> $random_text<BR>
> </BODY>
> </HTML>
> EOL
>
> the Best to All!
> --Dennis
>
In your code, rand() returns values from 0 to 3, not including 3 itself
(that is, greater than or equal to 0 and less than 3). Then int() truncates
that result, giving either 0, 1, or 2.
perldoc -f rand
perldoc -f int
The simple answer is to use rand(...) + 1.
Side note: why a hash and not an array?
--
David Hilsee
------------------------------
Date: Mon, 24 Sep 2001 05:30:18 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: sub key index sorting
Message-Id: <3BAEC3A0.BE49006@acm.org>
Scott Wessels wrote:
> I've append to the end of this post, my current attempts at this sort, and
> presently the sprintf routine beats the others out by over two-fold though
> I have concerns that it may not be the most efficient of routines.
Generally, any technique that allows you to use the "native" comparison of
the sort function will be the best performer, especially on large data sets.
Remember, any "inefficiencies" in the pre- and post-processing are O(N),
while the sort itself is O(N log N).
See http://www.effectiveperl.com/recipes/sorting.html and
http://www.sysarch.com/perl/sort_paper.html for some discussion.
Search for "packed-default sort" in the latter.
-- Dave Tweed
------------------------------
Date: 24 Sep 2001 05:42:38 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: This has got to be a bug
Message-Id: <9omh4e$71t$1@news.panix.com>
In article <slrn9qh9ag.5gs.dha@panix2.panix.com>,
David H. Adler <dha@panix.com> wrote:
>In article <9n231g$9ev$1@news.panix.com>, David Combs wrote:
>> In article <9m8poo$hj4$1@news.doit.wisc.edu>,
>> art blair <arthur@ablair.physics.wisc.edu> wrote:
>>>Thanx to all. \Q \E worked.
>>>I need to get a better perl book.
>>>
>>>Art.
>>
>> The "Bible" of perl is "Programming Perl", 3rd edition,
>> pub= O'Reilly.
>
>Actually, the "Bible" is the documentation that comes with perl... books
>get outdated pretty quickly.
One small question: just how often (seems like "never") is that
documentation *updated*?
For instance, from time to time an item from the faq gets
"autoposted" here, to cplmisc. People comment on it,
note errors in it, show better ways of saying things,
show better examples, etc, etc.
QUESTION: *when*, if ever, do those fixes get incorporated
*into* that comes-with-perl documentation?
(I've never seen it happen!)
So maybe a year or 18-month-old PP3 is in fact *more up to
date* than this doc that comes *with* a perl distribution?
>That said, as paper books go, you *would* be hard pressed to find a
>better candidate.
>--
>David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
------------------------------
Date: Mon, 24 Sep 2001 06:12:30 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: This has got to be a bug
Message-Id: <slrn9qtjmf.eug.mgjv@verbruggen.comdyn.com.au>
On 24 Sep 2001 05:42:38 GMT,
David Combs <dkcombs@panix.com> wrote:
> In article <slrn9qh9ag.5gs.dha@panix2.panix.com>,
> David H. Adler <dha@panix.com> wrote:
>>In article <9n231g$9ev$1@news.panix.com>, David Combs wrote:
>>> In article <9m8poo$hj4$1@news.doit.wisc.edu>,
>>> art blair <arthur@ablair.physics.wisc.edu> wrote:
>>>>Thanx to all. \Q \E worked.
>>>>I need to get a better perl book.
>>>>
>>>>Art.
>>>
>>> The "Bible" of perl is "Programming Perl", 3rd edition,
>>> pub= O'Reilly.
>>
>>Actually, the "Bible" is the documentation that comes with perl... books
>>get outdated pretty quickly.
>
> One small question: just how often (seems like "never") is that
> documentation *updated*?
On every release of Perl.
> For instance, from time to time an item from the faq gets
> "autoposted" here, to cplmisc. People comment on it,
> note errors in it, show better ways of saying things,
> show better examples, etc, etc.
>
> QUESTION: *when*, if ever, do those fixes get incorporated
> *into* that comes-with-perl documentation?
If the comments get submitted as a bug report, and that bug report
gets incorporated, then it should appear in the next release.
I wouldn't mind seeing the Perl distribution split up a bit more. The
documentation could be a separate package, and so could many of the
'standard' modules. That would allow for a more frequent update to the
documentation more easily. The modules can be kept up to date with the
CPAN module, but broken documentation, and broken scripts (like the
various perl* scripts) can't.
Martien
--
Martien Verbruggen |
Interactive Media Division | The gene pool could use a little
Commercial Dynamics Pty. Ltd. | chlorine.
NSW, Australia |
------------------------------
Date: Mon, 24 Sep 2001 05:57:37 GMT
From: NoSpam@Nevermind.com (Soren Andersen)
Subject: Re: using Inline.pm to distribute binary perl modules
Message-Id: <Xns912613EA8C187pspnR@204.127.36.1>
"Chris Dawson" <cdawson@webiphany.com> wrote in
<tne5i4efvsv100@corp.supernews.com>:
>I have written a perl module using Inline.pm. Fantastic module, I have
>to say. I now want to distribute the binary DLL that is created by
>Inline. I have another win32 NT machine where I want to run this script
>[...] I was hoping there would be some way that I could bundle the DLL
>that I see is residing deep within the _Inline directory, and use this
>from within my script without it attempting a recompile.
>Anyone have any tips for me here?
I do not know enough about Inline to offer specific advice regarding it,
other than that I am *pretty sure* you are asking in the wrong place; I
believe (I know for a fact) that there are Inline mailing lists -- asking
there would likely serve you better.
If someone was brandishing a firearm at me in order to extract an answer, I
would say you want to disribute binary win32 perl module code using PPM
(ActiveState's Perl Package Manager). I offer this only under (imaginary)
duress, however ;-).
Soren Andersen
------------------------------
Date: Mon, 24 Sep 2001 14:57:46 +1000
From: "aL" <nobody@nowhere.com>
Subject: Using URLs as hash keys
Message-Id: <9omehi$8qm$1@perki.connect.com.au>
Arvo all,
I thought I'd actually ask for some *preventative* advice for a change. I
was just wondering if anyone knew of any inherent dangers of using URLs as
keys in a hash. So far I haven't run into any problems, but I've got this
sneaking suspicion that an extra-long URL or a strange character might cause
havoc down the track. In particular would referencing a hash value using a
scalar variable to represent to the URL cause any problems? For instance:
$hash{$url} = "value";
For the curious, here is an example of the way I'll be using the $url keys:
<BEGIN CODE>
my @website_list = ("Yahoo!", "Google", "AltaVista", "HotBot");
my %data;
foreach my $website (@website_list) {
my $url = Find_URL ( $website );
# ( Just imagine that the Find_URL routine returns a URL)
$data{$url} = "blah";
}
foreach my $url (keys %data) {
print "URL: $url";
print "Value: $data{$url}";
}
<END CODE>
Does that look OK?
Thanks for your help,
aL
------------------------------
Date: Mon, 24 Sep 2001 07:10:51 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Using URLs as hash keys
Message-Id: <Xns91264A68B8C5Laocooneudoramailcom@62.153.159.134>
"aL" <nobody@nowhere.com> wrote in
news:9omehi$8qm$1@perki.connect.com.au:
> Arvo all,
>
> I thought I'd actually ask for some *preventative* advice for a change.
> I was just wondering if anyone knew of any inherent dangers of using
> URLs as keys in a hash. So far I haven't run into any problems, but
> I've got this sneaking suspicion that an extra-long URL or a strange
> character might cause havoc down the track. In particular would
> referencing a hash value using a scalar variable to represent to the
> URL cause any problems? For instance: $hash{$url} = "value";
Nothing wrong with that..
> For the curious, here is an example of the way I'll be using the $url
> keys:
>
> <BEGIN CODE>
> my @website_list = ("Yahoo!", "Google", "AltaVista", "HotBot");
> my %data;
> foreach my $website (@website_list) {
> my $url = Find_URL ( $website );
> # ( Just imagine that the Find_URL routine returns a URL)
> $data{$url} = "blah";
> }
>
> foreach my $url (keys %data) {
> print "URL: $url";
> print "Value: $data{$url}";
> }
> <END CODE>
>
> Does that look OK?
yep
------------------------------
Date: Mon, 24 Sep 2001 06:05:59 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Using URLs as hash keys
Message-Id: <slrn9qtja7.eug.mgjv@verbruggen.comdyn.com.au>
On Mon, 24 Sep 2001 14:57:46 +1000,
aL <nobody@nowhere.com> wrote:
> Arvo all,
>
> I thought I'd actually ask for some *preventative* advice for a change. I
> was just wondering if anyone knew of any inherent dangers of using URLs as
> keys in a hash.
Should work. Hash keys are just strings.
> For the curious, here is an example of the way I'll be using the $url keys:
[snip code]
> Does that look OK?
Looks fine to me.
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where
Commercial Dynamics Pty. Ltd. | would you put it?
NSW, Australia |
------------------------------
Date: Mon, 24 Sep 2001 17:00:13 +1000
From: "aL" <nobody@nowhere.com>
Subject: Re: Using URLs as hash keys
Message-Id: <9omll9$f2r$1@perki.connect.com.au>
> Should work. Hash keys are just strings.
Thanks for your help.
Does anyone know of any in-built limit to the size of keys?
aL
------------------------------
Date: Sun, 23 Sep 2001 22:58:07 -0700
From: Philip Wasson <pwasson@mindspring.com>
Subject: Re: Why are tabs converted to spaces?
Message-Id: <3BAECB6F.D27ABE8F@mindspring.com>
Thank you for trying!
I'm using Perl version 5.00404 with Apache Webserver version 1.3.3 on Solaris 7,
hosted by CommuniTech.Net.
"E.Chang" wrote:
>
> Ah. Apologies for the misunderstanding. Then I really can't tell what
> might be wrong. It must be peciliar to your specific environment. I
> tested with Perl 5.6.0 and 5.6.1 on Windows and Linux, and the problem
> does not occur. The tab character is correctly being written to the
> file. If you give some more information such as what OS you are using,
> version, and such, someone might recognize what is happening.
>
> --
> EBC
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1800
***************************************