[16188] in Perl-Users-Digest
Perl-Users Digest, Issue: 3600 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 19:19:06 2000
Date: Mon, 10 Jul 2000 16:18:55 -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: <963271134-v9-i3600@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 10 Jul 2000 Volume: 9 Number: 3600
Today's topics:
simple www: downloading randal's MANY articles? (David Combs)
Re: simple www: downloading randal's MANY articles? <tina@streetmail.com>
Re: simple www: downloading randal's MANY articles? (Randal L. Schwartz)
Re: simple www: downloading randal's MANY articles? (Malcolm Dew-Jones)
Re: simple www: downloading randal's MANY articles? (Bart Lateur)
Re: simple www: downloading randal's MANY articles? (Randal L. Schwartz)
Re: simple www: downloading randal's MANY articles? (Peter Corlett)
Re: simple www: downloading randal's MANY articles? (David Combs)
Re: simple www: downloading randal's MANY articles? (David Combs)
Re: simple www: downloading randal's MANY articles? (Tad McClellan)
Slow sockets <nbs@po.cwru.edu>
Re: Slow sockets <tony_curtis32@yahoo.com>
SMS with Swisscom (UCP via TCP) / Help needed <info@thomas-fahle.de>
Sockets, modifying and writing files on target server admin@web-design.net
some poorly described problem in WinNT [was: Hope this (jason)
Something other than int(), was(Re: Random number) ()
Re: Something other than int(), was(Re: Random number) (Neil Kandalgaonkar)
sort usage <gte941n@prism.gatech.edu>
Re: sort usage <ozette@imaginative-creations.com>
Re: sort usage <gte941n@prism.gatech.edu>
Re: sort usage <tina@streetmail.com>
Re: sort usage <gte941n@prism.gatech.edu>
Re: sort usage (Tad McClellan)
Re: sort usage (Abigail)
Re: sort usage <gellyfish@gellyfish.com>
Re: sort usage (Anno Siegel)
Re: sort usage (Anno Siegel)
Re: sort usage <iltzu@sci.invalid>
Re: sort usage (Anno Siegel)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Jul 2000 19:25:21 GMT
From: dkcombs@netcom.com (David Combs)
Subject: simple www: downloading randal's MANY articles?
Message-Id: <8k2mf1$6cn$1@slb6.atl.mindspring.net>
Have never yet written anything to access www;
want to try, but first with lots of help,
even if YOU write the few lines needed (to
get me started with *something* that works).
Randal has all these articles on his site, for
downloading. One set I did by hand (lynx),
article by article.
The other set, webtechniques articles, has
way too many for that, and besides the articles
themselves, each has a separate link to the code.
Were there an ftp site for it, I could use
mget and *.pl and *.html, but no ftp-site that I can
find.
So! Opportunity for perl quickie. But cookbook
has nothing about it. I don't yet even know how
to install a .tar.gz from cpan (can download, of
course; just did).
---
So, please, someone do this first one for me -- just
the few lines needed to download, say, foo.html from
site www.foo.com/bletch/.
(Once I see that, as "catalyst", I can proceed. Oh,
saw nothing in faq (faq3) that said how to do it;
most doc seems to be on doing things SERVER-side;
this is CLIENT-side.)
THANKS!
David
ps: please don't just tell me to read some doc;
once I've got this first thing to work, I'll understand
enough that I'll then be *able* to read something!
(especially randal's articles, all printed out
by then).
------------------------------
Date: 6 Jul 2000 19:58:16 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <8k2ocn$1ktg5$2@ID-24002.news.cis.dfn.de>
hi,
David Combs <dkcombs@netcom.com> wrote:
> The other set, webtechniques articles, has
> way too many for that, and besides the articles
> themselves, each has a separate link to the code.
> Were there an ftp site for it, I could use
> mget and *.pl and *.html, but no ftp-site that I can
> find.
are you sure you want to use perl for this?
why not wget? you could start wget with a depth
level that limits the recursion.
hm, ok, for perl you have to use
LWP::Simple
and probably HTML::Parser
> So! Opportunity for perl quickie. But cookbook
> has nothing about it. I don't yet even know how
> to install a .tar.gz from cpan (can download, of
> course; just did).
look at your perl documentation; there should
be some help on installing modules and even
help on the CPAN-module.
> ps: please don't just tell me to read some doc;
why not? if you want to start with something, the
docs are a good place, because there are many examples.
type perldoc perldoc on
your command line.
writing a script with LWP::Simple requires at
least some knowledge of perl.
regards,
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."
------------------------------
Date: 06 Jul 2000 13:21:23 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <m1wvizko1o.fsf@halfdome.holdit.com>
>>>>> "David" == David Combs <dkcombs@netcom.com> writes:
David> The other set, webtechniques articles, has
David> way too many for that, and besides the articles
David> themselves, each has a separate link to the code.
Maybe I'm the only one that finds it ironic that one of those articles
is specifically about mirroring a series of predictably formed URLs to
a local archive, which is exactly the problem faced here.
:-)
David - go read <http://www.stonehenge.com/merlyn/WebTechniques/col31.html>.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 6 Jul 2000 13:37:38 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <3964ee12@news.victoria.tc.ca>
Tina Mueller (tina@streetmail.com) wrote:
: hi,
: David Combs <dkcombs@netcom.com> wrote:
: > The other set, webtechniques articles, has
: > way too many for that, and besides the articles
: > themselves, each has a separate link to the code.
: > Were there an ftp site for it, I could use
: > mget and *.pl and *.html, but no ftp-site that I can
: > find.
: are you sure you want to use perl for this?
: why not wget? you could start wget with a depth
: level that limits the recursion.
: hm, ok, for perl you have to use
: LWP::Simple
: and probably HTML::Parser
Look for the get script that comes with (at least some versions of) Perl.
It is useful in its own right, and an example of solving one half of your
problem.
------------------------------
Date: Thu, 06 Jul 2000 20:50:26 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <3965f069.1191323@news.skynet.be>
Randal L. Schwartz wrote:
>Maybe I'm the only one that finds it ironic that one of those articles
>is specifically about mirroring a series of predictably formed URLs to
>a local archive, which is exactly the problem faced here.
>
>:-)
Yes, but will you allow it?
It depends on the time between subsequent requests,I guess.
--
Bart.
------------------------------
Date: 06 Jul 2000 14:06:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <m1aefvklxo.fsf@halfdome.holdit.com>
>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:
Bart> Yes, but will you allow it?
Bart> It depends on the time between subsequent requests,I guess.
Yeah, I block by recent total CPU timed used, so for simple HTML or
textfile pushes, it's not gonna hit very often, since those are
incredibly optimized.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 07 Jul 2000 09:54:04 GMT
From: abuse@cabal.org.uk (Peter Corlett)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <0Nh95.7$Fe1.94161989@bernard.mailbox.net.uk>
David Combs <dkcombs@netcom.com> wrote:
[...]
> Were there an ftp site for it, I could use mget and *.pl and *.html,
> but no ftp-site that I can find.
Try wget instead.
> So! Opportunity for perl quickie. But cookbook has nothing about
> it. I don't yet even know how to install a .tar.gz from cpan (can
> download, of course; just did).
I remember several nearly-there answers in the cookbook. Combine
them.
> So, please, someone do this first one for me -- just the few lines
> needed to download, say, foo.html from site www.foo.com/bletch/.
"wget -np -m http://foo.bar/baz/" does the trick for me. Any
difficult sites, I write a special-case script.
------------------------------
Date: 8 Jul 2000 06:51:55 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <8k6j2b$sdc$1@slb1.atl.mindspring.net>
In article <m1wvizko1o.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "David" == David Combs <dkcombs@netcom.com> writes:
>
>David> The other set, webtechniques articles, has
>David> way too many for that, and besides the articles
>David> themselves, each has a separate link to the code.
>
>Maybe I'm the only one that finds it ironic that one of those articles
>is specifically about mirroring a series of predictably formed URLs to
>a local archive, which is exactly the problem faced here.
>
>:-)
>
>David - go read <http://www.stonehenge.com/merlyn/WebTechniques/col31.html>.
>
OK, I've just downloaded it.
Now I have to figure out how to "install" cpan modules. :-)
(Someone suggested wget -- but I want to LEARN this
stuff...)
Thanks
------------------------------
Date: 8 Jul 2000 06:54:46 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <8k6j7m$6u1$1@nntp9.atl.mindspring.net>
In article <0Nh95.7$Fe1.94161989@bernard.mailbox.net.uk>,
Peter Corlett <abuse@cabal.org.uk> wrote:
>David Combs <dkcombs@netcom.com> wrote:
>[...]
>> Were there an ftp site for it, I could use mget and *.pl and *.html,
>> but no ftp-site that I can find.
>
>Try wget instead.
>
>> So! Opportunity for perl quickie. But cookbook has nothing about
>> it. I don't yet even know how to install a .tar.gz from cpan (can
>> download, of course; just did).
>
>I remember several nearly-there answers in the cookbook. Combine
>them.
>
>> So, please, someone do this first one for me -- just the few lines
>> needed to download, say, foo.html from site www.foo.com/bletch/.
>
>"wget -np -m http://foo.bar/baz/" does the trick for me. Any
>difficult sites, I write a special-case script.
>
Yes, wget is something I need to learn, too.
Will try it too.
David
------------------------------
Date: Sat, 8 Jul 2000 10:02:41 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: simple www: downloading randal's MANY articles?
Message-Id: <slrn8med41.oks.tadmc@magna.metronet.com>
On 8 Jul 2000 06:51:55 GMT, David Combs <dkcombs@netcom.com> wrote:
>Now I have to figure out how to "install" cpan modules. :-)
perldoc perlmodinstall
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 03 Jul 2000 12:28:42 -0400
From: "Noah B. Sandler" <nbs@po.cwru.edu>
Subject: Slow sockets
Message-Id: <3960BF3A.6E6F697F@po.cwru.edu>
I'm trying to retrieve data from web pages with a perl script. I've
done the same thing in C and VB, and it takes less than a second per
page to retrieve and process it. However, when I try using perl my
program takes about 20 seconds per page just to read in the web page.
I'm using "@x = <SOCK>;" to read in the web page all at once, and have
positively identified this statement as the source of the slowdown.
I've looked all over the web and can't see anyone doing anything much
differently.
If anyone could help me, I'd greatly appreciate it.
------------------------------
Date: 03 Jul 2000 11:41:06 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Slow sockets
Message-Id: <871z1b2ml9.fsf@limey.hpcc.uh.edu>
>> On Mon, 03 Jul 2000 12:28:42 -0400,
>> "Noah B. Sandler" <nbs@po.cwru.edu> said:
> I'm trying to retrieve data from web pages with a perl
> script. I've done the same thing in C and VB, and it
> takes less than a second per page to retrieve and
> process it. However, when I try using perl my program
> takes about 20 seconds per page just to read in the web
> page.
> If anyone could help me, I'd greatly appreciate it.
perldoc LWP
hth
t
--
"With $10,000, we'd be millionaires!"
Homer Simpson
------------------------------
Date: Fri, 07 Jul 2000 20:41:40 +0200
From: Thomas Fahle <info@thomas-fahle.de>
Subject: SMS with Swisscom (UCP via TCP) / Help needed
Message-Id: <39662464.89C140D4@thomas-fahle.de>
Hi,
is there an SMS-client in perl who is able
to do *UCP via TCP* especially with http://www.swisscom.ch
I have already searched freshmeat and CPAN.
All available tools stick to modem-connections.
sms_client (in C) will do things with modems,
the ucp over tcp lib isn't working corectly.
problems in detail:
getting the initial connection (auth) string right.
parsing IA5 characters
TiA
Thomas
------------------------------
Date: Sun, 09 Jul 2000 23:41:59 GMT
From: admin@web-design.net
Subject: Sockets, modifying and writing files on target server
Message-Id: <8kb2k5$iqo$1@nnrp1.deja.com>
Hi:
I am new to working with sockets. I have read some tutorials, connected
some basic sockets but that's it.
Here's what I need to learn how to do ... I learn fast, but there doesn't
seem to be any tutorials around which seem to tie all this together.
1. take data from web form input on the client machine
2. process data and open a socket to another machine
3. write the data to files on another machine on the net
Specifically, when someone registers a domain name, I want to take the
domain name and write the zone files to the primary DNS server which is on
another machine.
I need therefore some snippets which show me specifically how to
open a socket to the server
append to the named.conf file
write a new zone file for the domain
Ideally I'd like to automate this so that all I would have to do is restart
the nameserver service twice daily, and all the zone updates written, on
the server, would then be updated.
Can someone help with some snippets that I can hack away on or something?
Thanks in advance,
Eric Beck, BWSD
http://web-design.net/index.shtml mailto:admin@web-design.net
996 Basswood Avenue, Oshawa, ON L1H 2G7
Phone: 905 436 6814 Fax: 413 581 7439
================================================================
http://InstantDomainRegistration.com
~$15 US ($22 CDN) !!! Save Up To 57% on Domain Registration !!!
A Beck Web Servers and Design Company
================================================================
BECK WEB SERVERS & DESIGN - WHERE SUPPORT AND SERVICE ARE #1
================================================================
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 08 Jul 2000 02:02:22 GMT
From: elephant@squirrelgroup.com (jason)
Subject: some poorly described problem in WinNT [was: Hope this is the right group]
Message-Id: <MPG.13d128f6a481d425989777@news>
root writes ..
>i am using win32 perl AS ver perl 5.005 with IIS on WINNT Server I have
>completed the development and testing. During the process some of the
>web pages are forms and these forms are stored as text files. When ever
>required
>directories are created if they dont exist. All this was working until
>my machine has broken down.
>
>After rebuilting it completed and restoring my web site ( i do backups)
>configured IIS to run Perl. all the forms work great, however
>if directories are missing they are being created. If i create the
>the directories every thing works just file.
>
>
>Nothing as far i know, have done other then defaults. The IUSR_XXXXXPC
>id is used by the web server. and has Execute permissions on the virtual
>directory.
>
>
>Any hints at what i missed.
yeah you missed giving us any clues as to what you're problem is
you also missed how to use this newsgroup effectively
a) read the documentation for the Perl features that you're using and
make sure it's nothing simple and that you're using the features in
a similar way to the examples in the documentation
b) use a descriptive subject line
c) state your problem clearly
d) always provide code examples of where you think the problem is and
what you expect the code to be doing
e) make sure the problem is actually a Perl one .. is Perl giving you
any errors ?
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Sat, 08 Jul 2000 04:59:03 GMT
From: cabneySPAM@SPAM.SPAMcyberpass.net ()
Subject: Something other than int(), was(Re: Random number)
Message-Id: <ryy95.61686$T9.473023@news1.rdc1.sdca.home.com>
Ok, I'm responding to an old one, and the Subject was maybe a little
obscene... but wait!
In <slrn8hh4um.efl.abigail@ucan.foad.org> abigail counseled:
> On Fri, 28 Apr 2000 12:17:31 GMT, Chello <stephane@siw.ch> wrote:
> + I have a little problem I have to generate a random number with two limits
> + (upper limit and down limit) for example 1 and 4. When I call the script
>
> my $r = [1 .. 4] -> [rand 4];
Knowing this had to be sick and twisted in some clever way, I dug in.
What the hell does it do? I think that it is creating an anonymous
array containing the values one to four, then dereferencing to the
[rand 4th] element of the array and assigning the value found in the
[rand 4th element] to $r. The choice comes from the interval 1 - 4,
and dealing with the n-1 return value of rand has been abstracted to
an accession of the array index. That's pretty sick. And twisted.
But it's pretty !$# cool, too. <g>
But how fast is it?
Benchmark: timing 1000000 iterations of Abigails, straightforward...
Abigails: 21 wallclock secs (20.19 usr + 0.01 sys = 20.20 CPU)
straightforward: 9 wallclock secs ( 8.48 usr + 0.00 sys = 8.48 CPU)
Twisted Abby:
1: 250164
2: 250672
3: 249542
4: 249622
Straighforward?:
1: 248974
2: 250617
3: 249977
4: 250432
Conclusion: Abigail's is slooooow :(
8<----
#! /usr/bin/perl -w
use strict;
use Benchmark;
my ($r1, %h1 );
my ($r2, %h2 );
sub randint1 {
$r1 = [1 .. 4] -> [rand 4];
$h1{$r1}++; # useless fluff
}
sub randint2 {
$r2 = int( rand(4) + 1 );
$h2{$r2}++; # more fluff
}
timethese (1000000, {
'Abigails' => \&randint1,
'straightforward' => \&randint2,
});
print "Twisted Abby:\n";
print "$_: $h1{$_}\n" for (keys %h1);
print "\nStraighforward?:\n";
print "$_: $h2{$_}\n" for (keys %h2);
8<----
But, maybe I shouldn't have called it straightforward, because now I
have a question.
How do I get the magic auto-integerification thinger pointed at rand's
output? I thought adding an integer would be enough, but that didn't
work here (or I wouldn't have resorted to int()). Rearranging to place
the 1 ahead of rand() didn't change things (looking for bad juju...)
But in fact, rearranging things so that
$r2 = int( rand(4) ) + 1;
causes 'straightforward' to be as slow as 'Abigails'! Really wierd.
I mean, why should it be slower to add two integers then it is to add
a float with an integer?
Anyway, is there a faster way than what I found?
CA
--
Mighty Mouse is a cartoon. Superman is a real guy. No way a cartoon could beat
up a real guy! -- Teddy C. Abney
------------------------------
Date: Sun, 09 Jul 2000 12:18:20 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Re: Something other than int(), was(Re: Random number)
Message-Id: <8k9q63$hqf$1@localhost.localdomain>
In article <ryy95.61686$T9.473023@news1.rdc1.sdca.home.com>,
<cabneySPAM@SPAM.SPAMcyberpass.net> wrote:
>> my $r = [1 .. 4] -> [rand 4];
>
> That's pretty sick. And twisted.
>But it's pretty !$# cool, too. <g>
Unrelated note: you might like this too, which somebody posted to
this ng a while back:
$min = [ $x => $y ] -> [ $y <= $x ];
>But how fast is it?
[...]
>Conclusion: Abigail's is slooooow :(
No duh. [ ] creates a new anonymous array.
Although your testing was flawed, since you loaded in unnecessary
stuff into both subroutines.
>sub randint1 {
> $r1 = [1 .. 4] -> [rand 4];
> $h1{$r1}++; # useless fluff
>}
>
>sub randint2 {
> $r2 = int( rand(4) + 1 );
> $h2{$r2}++; # more fluff
>}
Benchmarking a+k versus b+k does not give the same results as a versus b.
-----------------------
#!/usr/bin/perl -w
use strict;
use Benchmark;
sub abigail {
[1 .. 4] -> [rand 4];
}
sub boring {
int (rand(4)) + 1;
}
timethese (1_000_000, { Abigail => \&abigail, Boring => \&boring } );
----------------------
Benchmark: timing 1000000 iterations of Abigail, Boring...
Abigail: 19 wallclock secs (18.17 usr + 0.05 sys = 18.22 CPU) @ 54884.74/s (n=1000000)
Boring: 1 wallclock secs ( 1.59 usr + 0.04 sys = 1.63 CPU) @ 613496.93/s (n=1000000)
>How do I get the magic auto-integerification thinger pointed at rand's
>output? I thought adding an integer would be enough, but that didn't
>work here (or I wouldn't have resorted to int()).
Nope, in perl, adding one to a number does not cause bizarre type changes.
However, if you ask for the 3.141592th element of an array, perl gives you
element 3, because a float makes no sense there.
>But in fact, rearranging things so that
>
> $r2 = int( rand(4) ) + 1;
>
>causes 'straightforward' to be as slow as 'Abigails'! Really wierd.
This can't be right. See above.
So let me get this straight: you want a random number between 1 and 4, faster
than int(rand(4)) + 1?
--
Neil Kandalgaonkar <neil@brevity.org>
------------------------------
Date: 3 Jul 2000 15:39:50 GMT
From: Benjamin David Garrison <gte941n@prism.gatech.edu>
Subject: sort usage
Message-Id: <8jqc46$6i$1@news-int.gatech.edu>
what exactly does this do?
@keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
--
Ben Garrison * ICQ#20300203 * IM ben628496 * www.ben.f2s.com
"I think, therefore I am not a Dawg"
------------------------------
Date: Mon, 03 Jul 2000 11:54:09 -0400
From: "Mr. Ozette Brown" <ozette@imaginative-creations.com>
To: Benjamin David Garrison <gte941n@prism.gatech.edu>
Subject: Re: sort usage
Message-Id: <3960B720.35A36075@imaginative-creations.com>
Benjamin,
Are you trying to sort the keys in your hash in ascending order?
Ozette
Benjamin David Garrison wrote:
> what exactly does this do?
>
> @keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
>
> --
> Ben Garrison * ICQ#20300203 * IM ben628496 * www.ben.f2s.com
> "I think, therefore I am not a Dawg"
--
Mr. Ozette J. Brown <President>
Imaginative Creations <webmaster@imaginative-creations.com>
A Website Development and Consulting Company.
http://www.imaginative-creations.com
------------------------------
Date: 3 Jul 2000 17:26:05 GMT
From: Benjamin David Garrison <gte941n@prism.gatech.edu>
Subject: Re: sort usage
Message-Id: <8jqibd$1da$1@news-int.gatech.edu>
I'm not sure what it's supposed to do. I'm new to perl, and I can't
figure out what it's doing. (I'm updating someone else's poorly
documented script)
Mr. Ozette Brown <ozette@imaginative-creations.com> wrote:
> Benjamin,
> Are you trying to sort the keys in your hash in ascending order?
> Ozette
> Benjamin David Garrison wrote:
>> what exactly does this do?
>>
>> @keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
>>
>> --
>> Ben Garrison * ICQ#20300203 * IM ben628496 * www.ben.f2s.com
>> "I think, therefore I am not a Dawg"
> --
> Mr. Ozette J. Brown <President>
> Imaginative Creations <webmaster@imaginative-creations.com>
> A Website Development and Consulting Company.
> http://www.imaginative-creations.com
--
Ben Garrison * ICQ#20300203 * IM ben628496 * www.ben.f2s.com
- As a general rule, you should never spit into the wind, or against
an opposing gravitational force.
------------------------------
Date: 4 Jul 2000 00:00:13 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: sort usage
Message-Id: <8jr9ec$15knk$1@ID-24002.news.cis.dfn.de>
hi,
Benjamin David Garrison <gte941n@prism.gatech.edu> wrote:
> what exactly does this do?
> @keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
what type of data is in $rec{key} ?
if it's an array, you should better write
@keys = sort { @{$rec{$a}} cmp @{$rec{$b}} } keys %rec;
then it compares the length of the arrays.
if it's a scalar, then you should better write
@keys = sort { $rec{$a} cmp $rec{$b} } keys %rec;
then it compares the values in %rec and returns
the keys in that order.
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."
------------------------------
Date: 4 Jul 2000 03:02:02 GMT
From: Benjamin David Garrison <gte941n@prism.gatech.edu>
Subject: Re: sort usage
Message-Id: <8jrk3a$bel$1@news-int.gatech.edu>
Tina Mueller <tina@streetmail.com> wrote:
<snip>
thanks for the reply, but I figured out my problem. It was a product of
my inexperience in perl...I didn't know that 'key' was a function. =)
sorry if I wasted anyone's time.
--
Ben Garrison * ICQ#20300203 * IM ben628496 * www.ben.f2s.com
"Well, it is trivial, so I do not have to explain it!" - Vladamir Lebedev,
talking about projecting the equation e^(3t) onto the subspace of
equations, <1, e^t, e^(2t)>
------------------------------
Date: Mon, 3 Jul 2000 22:03:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: sort usage
Message-Id: <slrn8m2hg0.d5u.tadmc@magna.metronet.com>
On 3 Jul 2000 15:39:50 GMT, Benjamin David Garrison <gte941n@prism.gatech.edu> wrote:
>what exactly does this do?
>
>@keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
Sorts the %rec hash by value (as strings) and makes warnings
about using one-element slices instead of scalars.
Turn on warnings, change 2 characters, and it looks like
the FAQ answer.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 04 Jul 2000 02:37:06 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: sort usage
Message-Id: <slrn8m32i9.59a.abigail@alexandra.delanet.com>
Benjamin David Garrison (gte941n@prism.gatech.edu) wrote on MMCDXCVIII
September MCMXCIII in <URL:news:8jqc46$6i$1@news-int.gatech.edu>:
`' what exactly does this do?
`'
`' @keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
Something very, very, very weird. It's taking hash slices, and comparing
them as if they were scalar strings.
Bizarrrrrr!
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: 4 Jul 2000 00:22:58 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: sort usage
Message-Id: <8jr78i$4gv$1@orpheus.gellyfish.com>
On 3 Jul 2000 15:39:50 GMT Benjamin David Garrison wrote:
> what exactly does this do?
>
> @keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
>
It doesnt do anything. If it was :
@keys = sort { $rec{$a} cmp $rec{$b} } key %rec;
then it would be creating an array of the keys of the hash sorted by the
values in the hash.
/J\
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
Date: 4 Jul 2000 09:02:57 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sort usage
Message-Id: <8js981$i39$1@lublin.zrz.tu-berlin.de>
Jonathan Stowe <gellyfish@gellyfish.com> wrote in comp.lang.perl.misc:
>On 3 Jul 2000 15:39:50 GMT Benjamin David Garrison wrote:
>> what exactly does this do?
>>
>> @keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
>>
>
>It doesnt do anything. If it was :
>
> @keys = sort { $rec{$a} cmp $rec{$b} } key %rec;
>
>then it would be creating an array of the keys of the hash sorted by the
>values in the hash.
It would, if the next-to-last word were "keys" instead of "key".
Anno
------------------------------
Date: 4 Jul 2000 09:12:07 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sort usage
Message-Id: <8js9p7$i4i$1@lublin.zrz.tu-berlin.de>
Tad McClellan <tadmc@metronet.com> wrote in comp.lang.perl.misc:
>On 3 Jul 2000 15:39:50 GMT, Benjamin David Garrison <gte941n@prism.gatech.edu> wrote:
>
>>what exactly does this do?
>>
>>@keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
>
>
>Sorts the %rec hash by value (as strings)
No. It compares the lengths of the hash slices @rec{$a} and
@reg{$b}, which are both 1, and sorts accordingly.
Anno
------------------------------
Date: 4 Jul 2000 12:40:50 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: sort usage
Message-Id: <962714308.1118@itz.pp.sci.fi>
In article <8js9p7$i4i$1@lublin.zrz.tu-berlin.de>, Anno Siegel wrote:
>Tad McClellan <tadmc@metronet.com> wrote in comp.lang.perl.misc:
>>On 3 Jul 2000 15:39:50 GMT, Benjamin David Garrison <gte941n@prism.gatech.edu> wrote:
>>>
>>>@keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
>>
>>Sorts the %rec hash by value (as strings)
>
>No. It compares the lengths of the hash slices @rec{$a} and
>@reg{$b}, which are both 1, and sorts accordingly.
Huh? When did the scalar value of slices change?
$ perl -wle 'my %foo = (a => "A"); print scalar @foo{a}'
Scalar value @foo{a} better written as $foo{a} at -e line 1.
A
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method." -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: 5 Jul 2000 09:14:46 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sort usage
Message-Id: <8juua6$k9p$1@lublin.zrz.tu-berlin.de>
Ilmari Karonen <usenet11142@itz.pp.sci.fi> wrote in comp.lang.perl.misc:
>In article <8js9p7$i4i$1@lublin.zrz.tu-berlin.de>, Anno Siegel wrote:
>>Tad McClellan <tadmc@metronet.com> wrote in comp.lang.perl.misc:
>>>On 3 Jul 2000 15:39:50 GMT, Benjamin David Garrison <gte941n@prism.gatech.edu> wrote:
>>>>
>>>>@keys = sort { @rec{$a} cmp @rec{$b} } keys %rec;
>>>
>>>Sorts the %rec hash by value (as strings)
>>
>>No. It compares the lengths of the hash slices @rec{$a} and
>>@reg{$b}, which are both 1, and sorts accordingly.
>
>Huh? When did the scalar value of slices change?
>
> $ perl -wle 'my %foo = (a => "A"); print scalar @foo{a}'
> Scalar value @foo{a} better written as $foo{a} at -e line 1.
You're right. Slices aren't arrays. I thought I knew that.
Anno
------------------------------
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 3600
**************************************