[18955] in Perl-Users-Digest
Perl-Users Digest, Issue: 1150 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 18 03:07:23 2001
Date: Mon, 18 Jun 2001 00:05:10 -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: <992847909-v10-i1150@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 18 Jun 2001 Volume: 10 Number: 1150
Today's topics:
A question on some basic things <khchan2@csis.hku.hk>
Re: A question on some basic things (Chris Fedde)
Re: Apache 1.3.20 STDIN 2K buffer limit? (isterin)
Re: Autoflush problem with Perl CGI under Apache (David Efflandt)
compiling with perl <patelnavin@icenet.net>
Re: Connect to another pc. karl@localhost.blorg
Re: Execute command within the script karl@localhost.blorg
Filehandles and close. <taboo@comcen.com.au>
finding a file in a directory?? (Nina)
Re: FORM CGI sorting (Chris Fedde)
Re: FORM CGI sorting <taboo@comcen.com.au>
Re: HTML input box variables? <ed@krypton.mikroneuvos.fi>
Re: Mix JS variables with Perl (David Efflandt)
perl with emacs <lesander@hotmail.com>
Re: Perl2Exe Decompiler? <marc@hvc.rr.com>
Re: Perl2Exe Decompiler? <sub235k@home.com>
Re: Perl2Exe Decompiler? <kevin@vaildc.net>
Re: possible to pass a parameter from href to cgi scrip karl@localhost.blorg
Re: Rounding down a float <pne-news-20010618@newton.digitalspace.net>
Re: sorting a hash on part of its value? (Chris Fedde)
Re: sorting a list of files from a directory (Raja)
Re: Sorting hash (Chris Fedde)
Re: Sorting versions of a file, Help needed (Chris Fedde)
Re: Why is perl faster then Tcl karl@localhost.blorg
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 18 Jun 2001 11:12:37 +0800
From: Bernard Chan <khchan2@csis.hku.hk>
Subject: A question on some basic things
Message-Id: <3B2D71A5.8000202@csis.hku.hk>
I would like to know why it is incorrect to say that
execution of compiled programs is often faster than
that of interpreted programs.
------------------------------
Date: Mon, 18 Jun 2001 04:12:06 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: A question on some basic things
Message-Id: <qcfX6.130$T3.171505664@news.frii.net>
In article <3B2D71A5.8000202@csis.hku.hk>,
Bernard Chan <khchan2@csis.hku.hk> wrote:
>I would like to know why it is incorrect to say that
>execution of compiled programs is often faster than
>that of interpreted programs.
>
So would we all...
You could probably find lots of good articles about this topic by typing
the key words from the above paragraph into google.
Good Luck
--
This space intentionally left blank
------------------------------
Date: 17 Jun 2001 21:13:26 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: Apache 1.3.20 STDIN 2K buffer limit?
Message-Id: <db67a7f3.0106172013.52461b38@posting.google.com>
How about using the CGI.pm module to do that for you. See perldoc CGI
after you install it, since I can't recall the syntax for reading
files right now.
Ilya Sterin
assi@io.com wrote in message news:<3B2CFCC2.456EF1F8@io.com>...
> I've cross posted this to the Perl, Apache, and CGI group because I'm
> not sure where the exact problem is. I'm using Apache 1.3.20 on Windows
> 98 second edition. I'm using Perl 5.6.0 binary build 618 distributed by
> ActiveState. I'm using home built CGI code that works as intended on
> Apache on Red Hat Linux.
>
> The problem is reading in from a binary file upload on a multi-part-form
> post. My read seems to be truncated at 2k bytes and should be more like
> 20k bytes.
>
> I repeat this code works fine on Apache on Linux and I a trying to port
> it to Apache on Windows.
>
> The line of code is:
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> I've tried several read alternatives to no avail. I've checked the
> length of $buffer after each different type of read and I get between
> 2401 and 2456.
>
> The variable $ENV{'CONTENT_LENGTH'} contains the value 28997.
>
> The alternatives I have tried are reading in a loop, reading using <>and
> reading using a 4k constant as the length. They all return the same
> negative result.
>
> For example as DEBUG CODE ONLY I tried this.
> $lr1 = sysread(STDIN, $buffer, 4096);
> $lr2 = sysread(STDIN, $buffer2, 4096);
>
> $lr1 == 2407
> $lr2 == 0
> $ENV{'CONTENT_LENGTH'} == 28997
>
>
> Is there a constant in Apache 1.3.20 that limits the post input buffer
> (STDIN) size?
>
> Where does $ENV{'CONTENT_LENGTH'} get it's value from? Is it checking
> an eof pointer on STDIN?
>
> Is there some smarter way to read in from STDIN?
>
> Thanks,
> You can also reach me at eric@assi.net. I will post any postive
> responses.
------------------------------
Date: Mon, 18 Jun 2001 05:02:12 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Autoflush problem with Perl CGI under Apache
Message-Id: <slrn9ir2qk.o0c.see-sig@typhoon.xnet.com>
On Sat, 16 Jun 2001 22:13:14 +0100, Kaya <Kaya@NoSpamPlease.net> wrote:
> I have taken on the daunting task of attempting to get some Perl CGI scripts
> written (I use the term loosely) by a third party for my companies website,
> currently running on an IIS server which is being moved shortly to a new
> host running Apache.
> I have been successful so far by testing it on some free webspace on a
> commercial Internet server running Apache with Perl5 but would like to be
> able to test it offline on my home Linux Box (Also running Apache with
> Perl5) so that I can debug errors from the console. (No telnet access to
> test server).
> Apache reports "Premature end of script headers" in the Error log when
> linking to any of the scripts. All the help files regarding this error
> points to it being related to buffer flushing and suggests using $| = 1;
> before all print statement blocks.
> However the same script runs OK on the test Internet server !
> This indicates to me that the commercial server has somehow globally enabled
> Autoflushing for file handles used by Perl CGI scripts to send text to the
> browser.
It has nothing to do with autoflush. That isn't needed for output from
normal Perl CGI scripts.
What error do you get when you run one of those scripts in the shell
[note that the current dir (.) may not be in your PATH]:
./scriptname.cgi
Either the path to perl is incorrect or you edited the scripts in Windows
and expect them to run in Linux. Windows ends lines with CR-LF (^M^J or
\015\012) pairs and Linux (Unix) just uses LF (^J or \012). The error
may not be apparent if bash says it can't find perl when it really can't
find "perl^M" and ^M really is an invisible carriage return on screen.
When you uploaded them to the internet test server maybe you properly used
ASCII text mode for FTP transfer which converts to proper line endings.
When you copied them over from your Windows drive you did not. A quick
way to fix them if you have the 'pine' package installed is to load the
script into the 'pico' editor and just do space, backspace, then save the
script.
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Mon, 18 Jun 2001 11:26:08 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: compiling with perl
Message-Id: <9gk544$9hake$1@ID-93885.news.dfncis.de>
any information on creating self executable binaries out of the source code?
i know all about perl2exe, but i would like to know if this could run as CGI
application? is it possible to encrypt the perl source code, so no one can
see it, and there should not be any decompiler for it so that it would give
the source ditto from the original script.
any help will greatly appreciated!
thanks
------------------------------
Date: Mon, 18 Jun 2001 00:55:00 -0500
From: karl@localhost.blorg
Subject: Re: Connect to another pc.
Message-Id: <3B2D97B4.1A317006@localhost.blorg>
Please post the password and ip address of the machine so we can
test this out. ;)
Javier Jara wrote:
> =
> Hi there !
> I=B4m trying to connect a share from another pc with the following
> Programm but I really don=B4t know what is wrong !
> Can you tell me that ? Thanks !
> ---
> Xavier
> =
> ******************************
> use Win32::NetResource;
> $Password =3D "";
> $UserName =3D "administrator";
> $Connection =3D 1;
> =
> %NETRESOURCE =3D {
> 'Scope' =3D> RESOURCE_GLOBALNET,
> 'Type' =3D> RESOURCETYPE_DISK,
> 'DisplayType' =3D> RESOURCEUSAGE_CONNECTABLE,
> 'Usage' =3D> RESOURCEUSAGE_CONTAINER,
> 'LocalName' =3D> "D\:",
> 'RemoteName'=3D> "TEMP",
> 'Comment'=3D> "test",
> 'Provider'=3D> "PC_01",
> };
> Win32::NetResource::AddConnection(
> \%NETRESOURCE,$Password,$UserName,$Connection);
> ******************************
------------------------------
Date: Mon, 18 Jun 2001 00:33:00 -0500
From: karl@localhost.blorg
Subject: Re: Execute command within the script
Message-Id: <3B2D928C.BA530529@localhost.blorg>
yc wrote:
>
> How to execute a command within a perl script?
See the documentation in perlop under `STRING`, or for sytem, or for
exec.
------------------------------
Date: 18 Jun 2001 14:53:57 +1000
From: "Kiel R Stirling" <taboo@comcen.com.au>
Subject: Filehandles and close.
Message-Id: <3b2d8965$1@nexus.comcen.com.au>
Hi all,
My question is on filehandles.
If you open a file like so
open F, '/etc/hosts.allow' or die $!;
and then loop through the file in a while loop
while( <F> ) {
# do something..
}
At this point is there a need to call close on the filehandle?
Doesn't while( <F> ) imply while the filehandle is open?
So a call to close is really pointless, wasteful!
Any Idea's??
Regards,
Kiel R Stirling
------------------------------
Date: 17 Jun 2001 22:58:47 -0700
From: nina_samimi@yahoo.com.au (Nina)
Subject: finding a file in a directory??
Message-Id: <52fb0298.0106172158.5e1bf8d5@posting.google.com>
Hi,
> How can I find an specific file in a directory? Is there anyway I
> can search
> for a file like Unix commands "ls -tr what.*.4Jun.*" ???
>
> Thanks,
> Nina
------------------------------
Date: Mon, 18 Jun 2001 03:37:14 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: FORM CGI sorting
Message-Id: <KHeX6.126$T3.190603264@news.frii.net>
In article <64c127b5.0106170624.6e5c5580@posting.google.com>,
Razib <raldanash@yahoo.com> wrote:
>
>foreach $key(keys%FORM)
>{if $key=~ /WhatevertagIuse/)
>{blah blah [print to screen and pipe to sendmail];}
>
>I know I'm not guaranteed an order out of the hash, but every time I
>do it, it get's the same order over and over, no matter what I put in
>as values.
>
Hashes are orderd by the hash code of the key value. so if the hash always
has the same keys the value is always the same.
I'd replace your foreach with something that includes a sort:
foreach $key (sort keys %FORM)
or
foreach $key (sort {substr(5,3,$a) <=> substr(5,3,b)} keys %FORM}
--
This space intentionally left blank
------------------------------
Date: 18 Jun 2001 15:06:56 +1000
From: "Kiel R Stirling" <taboo@comcen.com.au>
Subject: Re: FORM CGI sorting
Message-Id: <3b2d8c70$1@nexus.comcen.com.au>
>or maintain a master list in your code
>@fields=qw(name,address,city);
>foreach $key (@fields) {
> if (exists $FORM{key}) {
> # blah blah
> }
>}
>
gnari
This I like
Cool ;)
------------------------------
Date: 18 Jun 2001 04:07:31 +0300
From: Edvard Majakari <ed@krypton.mikroneuvos.fi>
Subject: Re: HTML input box variables?
Message-Id: <871yoi61f0.fsf@krypton.mikroneuvos.fi>
Keywords: mail
> Let's say a beginner is wanting some code to mail some details, and
> someone gives a solution like:
>
> open(MAIL,"|mail $to");
Yes, but such was not the case in the message concerned. Even though that
we have to admit that we don't know whether it would contain code like
that, or anything equally insecure. I'd still strive for kinder approach,
like simply saying that "You'd probably should consider always using -T in
your CGI scripts in order to make them less vulnerable to malicious
attacks" or something along those lines.
--
# Edvard http://krypton.mikroneuvos.fi/~ed/ 040 7150 969
"And in conclusion," the speaker said, "truly understanding the overall
teaching of Scripture requires that one disregard problematic passages
such as the 'Do not resist evil.' in the Sermon on the Mount that was
brought up earlier." -"I agree completely," the master said, "To get a
good view of the forest, it is essential to chop down all the trees that
keep obstructing your view." -- Jonathan Hayward
------------------------------
Date: Mon, 18 Jun 2001 05:42:08 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Mix JS variables with Perl
Message-Id: <slrn9ir55g.o0c.see-sig@typhoon.xnet.com>
On Sun, 17 Jun 2001, BUCK NAKED1 <dennis100@webtv.net> wrote:
>
> Re: Mix JS variables with Perl
>
> tony_curtis32@yahoo.com (Tony Curtis)
>
>> dennis100@webtv.net (BUCK NAKED1) said:
>
> Sorry about the re-post, but I wanted to let you know where I'm at with
> this. The below coding works, but returns $ref. How do I get $ref
> interpreted? Instead of $ref, it should return a URL.
>
> $ref = '<script>document.write(document.referrer)</script>'; $query =
> new CGI; $cookie = $query->cookie(-name=>'drf', -value=>'$ref',
> expires=>'+30s'); print $value = $cookie->value(['$ref']);
>
> Single quotes prevent variable interpolation. Lose the quotes around
> $ref. If you need to interpolate a variable into a string, use
> double-quotes (or possibly "." to concatenate variables and literals, or
> possibly sprintf() depending on what you're trying to do).
> hth
> t
>
> I had already tried sprintf, double quotes, etc. and that didn't work
> either. Can you see any other reason why $ref is not interpolating?
What part of "Lose the quotes around $ref." don't you understand? Drop
the quotes entirely around ALL $ref. That part if it works for me. But I
don't think any browser is going to act on JavaScript in a cookie,
not to mention special characters escaped. For example (wordwrapped):
print $query->header(-content=>'text/html',-cookie=>$cookie);
(offline mode: enter name=value pairs on standard input)
Set-Cookie:
drf=%3Cscript%3Edocument.write%28document.referrer%29%3C%2Fscript%3E;
path=/./mytest; expires=Mon, 18-Jun-2001 05:23:40 GMT
Date: Mon, 18 Jun 2001 05:23:10 GMT
Content: text/html
Content-Type: text/html
In order to do what you want to you would have to load a page with
JavaScript, which would set and submit the value to a CGI, which would set
the cookie with the actual value submitted and load the content (and pray
that the user has JavaScript enabled).
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Sun, 17 Jun 2001 22:38:17 -0700
From: Les Ander <lesander@hotmail.com>
Subject: perl with emacs
Message-Id: <9gk3o9$2tj$1@nntp.Stanford.EDU>
Hi,
can some one tell me what are the useful commands
for debugging perl in emacs (i.e. going to the error etc).
thanks
--
-----------------X--------------X-------
------------------------------
Date: Mon, 18 Jun 2001 01:05:54 GMT
From: "Marc" <marc@hvc.rr.com>
Subject: Re: Perl2Exe Decompiler?
Message-Id: <StcX6.216904$f85.32872917@typhoon.nyroc.rr.com>
> > "Kevin Michael Vail" <kevin@vaildc.net> wrote in message
> > news:170620011958511367%kevin@vaildc.net...
> When you run a .exe file produced by perl2exe, I believe that it
> unpacks the contents into a temp directory (C:\WINDOWS\TEMP on my
> system) and then basically runs an embedded Perl interpreter on them.
> If you can somehow run the .exe but kill it before it has a chance to
> clean up those files, you might be able to recover the scripts you're
> trying to edit. --Or maybe not, if I'm mistaken about how it works,
> but it might be worth a try.
I watched my temp directory after executing one of my programs, but the
contents didn't change one bit.
Any other ideas? :-)
Thanks,
Marc
------------------------------
Date: Mon, 18 Jun 2001 01:45:30 GMT
From: "Mark and Christine McCain" <sub235k@home.com>
Subject: Re: Perl2Exe Decompiler?
Message-Id: <_2dX6.93255$qc.11676326@news1.rdc1.va.home.com>
"Marc" <marc@hvc.rr.com> wrote in message
news:zNaX6.216807$f85.32779643@typhoon.nyroc.rr.com...
> converted by Perl2Exe. This decompiler is called "UnPerl", was written by
> "Spot //UCL", and has a file name of "UCL!UPRL.RAR." I can't find this
> program ANYWHERE on the Net and trust me I searched every possible search
The reason that you can't find this program is because Spot//UCL is a hacker
consortium, and they "move" around a lot. I have firends in low places and
when I get the time I will ask them to try to dig it up for me, but you are
probably not going to find it by legitimate means.
------------------------------
Date: Sun, 17 Jun 2001 23:04:49 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Perl2Exe Decompiler?
Message-Id: <170620012304490664%kevin@vaildc.net>
In article <StcX6.216904$f85.32872917@typhoon.nyroc.rr.com>, Marc
<marc@hvc.rr.com> wrote:
> > > "Kevin Michael Vail" <kevin@vaildc.net> wrote in message
> > > news:170620011958511367%kevin@vaildc.net...
>
> > When you run a .exe file produced by perl2exe, I believe that it
> > unpacks the contents into a temp directory (C:\WINDOWS\TEMP on my
> > system) and then basically runs an embedded Perl interpreter on them.
> > If you can somehow run the .exe but kill it before it has a chance to
> > clean up those files, you might be able to recover the scripts you're
> > trying to edit. --Or maybe not, if I'm mistaken about how it works,
> > but it might be worth a try.
>
> I watched my temp directory after executing one of my programs, but the
> contents didn't change one bit.
Hunh. I found all kinds of interesting stuff in mine when my program
crashed (Perl/Tk program).
> Any other ideas? :-)
I seem to be fresh out. Oh, well, I tried.
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)
------------------------------
Date: Mon, 18 Jun 2001 00:07:04 -0500
From: karl@localhost.blorg
Subject: Re: possible to pass a parameter from href to cgi script?
Message-Id: <3B2D8C78.F8424C28@localhost.blorg>
Try passing them as http://some.url.com?name1=val1&name2=val2 etc.
Seems you're in the wrong group though. :)
Jana Cole wrote:
> Can I pass an identifying parameter in the link's HTML somehow?
------------------------------
Date: Mon, 18 Jun 2001 08:44:12 +0200
From: Philip Newton <pne-news-20010618@newton.digitalspace.net>
Subject: Re: Rounding down a float
Message-Id: <7o8ritk6sv2bhm9jfmionpkpj36q1ftvq7@4ax.com>
On Sun, 17 Jun 2001 19:45:18 GMT, PropART <temp1@williamc.com> wrote:
> So if I'm always working with positive floats then I guess I'm OK...
If all your floats are positive then int() and POSIX::floor() should be
equivalent, yes.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Mon, 18 Jun 2001 03:54:21 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: sorting a hash on part of its value?
Message-Id: <NXeX6.128$T3.191580160@news.frii.net>
In article <m3u21lldie.fsf@dhcp9-173.support.tivoli.com>,
Ren Maddox <ren@tivoli.com> wrote:
>On Tue, 12 Jun 2001, m.grimshaw@salford.ac.uk wrote:
>
>> @names = sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/,
>> $USER{$a})[10] } keys %USER;
>>
>> I get:
>> Can't use subscript on split at ./admin.cgi line 394, near "10]"
>> Can't use subscript on split at ./admin.cgi line 394, near "10]"
>> syntax error at ./admin.cgi line 394, near "] }"
>>
>> Which is more or less what I've been getting each time I've tried
>> it.
>
>You don't have enough parens (neither did the example that you were
>given). You can only subscript a split by putting parens around the
>entire split:
>
> @names = sort { ( split /¬/, $USER{$b} )[10] <=>
> ( split /¬/, $USER{$a} )[10] } keys %USER;
>
>If %USER is very big, you'll be better off with a Schwartzian
>Transform (or GRT):
>
> @names = map { $_->[1] }
> sort { $_->[0] <=> $_->[0] }
> map { [ ( split /¬/, $USER{$_} )[10], $_ ] }
> keys %USER;
>
Schwartzian Transform and other caching methods for sorting are
documented at
http://www.5sigma.com/perl/recipes.html
GRT is defined in
http://www.sysarch.com/perl/sort_paper.html
Good Luck
--
This space intentionally left blank
------------------------------
Date: 17 Jun 2001 23:02:04 -0700
From: raja@apexmail.com (Raja)
Subject: Re: sorting a list of files from a directory
Message-Id: <bd4c3646.0106172202.17d1759a@posting.google.com>
Hi,
Perhaps you could use a different approach?
$dir = "full path to dir";
open LS, "/bin/ls -1rt $dir|"; #Use ls to sort the files in the order you want
@sortedFileList = <LS>;
print "Sorted on last Modified: @sortedFileList \n";
Please note that I have used -1{one} not 'l'{el}.
Regards,
Nagaraj.
iburnedmyfingers@hotmail.com (Zsa Zsa) wrote in message news:<TluV6.29$SH4.52925@nnrp2.sbc.net>...
> I am looking for the best way to sort files within a directory for the
> purpose of listing.
> My ultimate goal is to sort the files in order of last modified (most
> recent at top of list).
> I developed this:
>
> opendir DIRH, "/path/tofolder" or die "couldn't open: $!";
> foreach (sort { -M $a <=> -M $b } readdir DIRH) {
> $file = $_;
> @info = stat ($file);
> @date = localtime($info[9]);
> $year = sprintf("%d-%d-%d\n",$date[4]+1,$date[3],$date[5]+1900);
> $time = "$date[2]:$date[1]";
> $lastmodified = "$year $time";
> ($filename) = $file =~ m!([^/]*)$!;
> print "<tr><td><a
> href=\"http://www.url.com/$filename\">$filename</a></td><td>$lastmodified
> </td></tr>";
> }
> closedir DIRH or die "couldn't close directory: $!";
>
> which seems to do custom sorts fine, but then the $lastmodified variable
> is always 12-31-1969 16:0
>
> so i tried this:
>
> foreach $file (</path/tofolder/*>) {
> @info = stat ($file);
> @date = localtime($info[9]);
> $year = sprintf("%d-%d-%d\n",$date[4]+1,$date[3],$date[5]+1900);
> $time = "$date[2]:$date[1]";
> $lastmodified = "$year $time";
> ($filename) = $file =~ m!([^/]*)$!;
> print "<tr><td><a
> href=\"http://www.url.com/$filename\">$filename</a></td><td>$lastmodified
> </td></tr>";
> }
>
> which displays the $lastmodified variable as a current date and time, but
> I cannot find a way to customize the sort of the list.
>
> I'm pretty new at PERL, so I'm sure I'm missing some simple coding trick
> that will solve my problem. Can anyone help?
------------------------------
Date: Mon, 18 Jun 2001 04:03:58 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Sorting hash
Message-Id: <O4fX6.129$T3.190606848@news.frii.net>
In article <3B2B3F14.B6E9CFF9@salford.ac.uk>,
Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote:
>
>
>Ron Anderson wrote:
>>
>> Using the sample hash below:
>>
>> $shash{"student1"} = join("\t", ("bob", "larson", "room5"));
>> $shash{"student2"} = join("\t", ("ron", "anderson", "room4"));
>> $shash{"student3"} = join("\t", ("dave", "lee", "room2"));
>> $shash{"student4"} = join("\t", ("tim", "barker", "room3"));
>> $shash{"student5"} = join("\t", ("roger", "farley", "room1"));
>>
>> how could I sort this %shash by last name?
>>
>> Thanks!
>
>I asked the same thing a few weeks back (how to sort a hash on _part_ of
>its value) and was given the following by some kind soul which is very
>efficient compared to the mangled code I had before (I was sorting on
>numbers so I've changed the <=> to cmp):
>
> @names = sort {(split(/¬/, $shash{$b}))[1] cmp (split(/¬/,
>$shash{$a}))[1] } keys %shash;
>
>my delimiter was '¬' - you'd need to change the delimiter in the split
>above to what you have.
If the dataset is small then your sort works fine. If the data set is near
memory size then using the Schwartzian Transform might be useful
http://www.5sigma.com/perl/schwtr.html
or the GRT
http://www.sysarch.com/perl/sort_paper.html
If your data is very large then using an external sort like the unix
command line sort, or better yet an ordered database file format like
BerkeleyDB BTREE or even mySQL.
Good Luck
--
This space intentionally left blank
------------------------------
Date: Mon, 18 Jun 2001 03:45:44 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Sorting versions of a file, Help needed
Message-Id: <IPeX6.127$T3.191280640@news.frii.net>
In article <3B24F9A3.95A3F3D7@mortgagestats.com>,
Andras Malatinszky <andras@mortgagestats.com> wrote:
>
>
>"Godzilla!" wrote:
>
>Use of a hash for programming should be your last choice
>
>> when a simple associative array or a common array could
>> be used
>
>What is the difference between a hash and a "simple associative array?"
>
"Hash" is colloquial Perl for "associative array." It derives from the
computer science term for the data structure used inside perl to store these
things.
Good Luck
--
This space intentionally left blank
------------------------------
Date: Mon, 18 Jun 2001 00:37:15 -0500
From: karl@localhost.blorg
Subject: Re: Why is perl faster then Tcl
Message-Id: <3B2D938B.CB2D4C02@localhost.blorg>
Q: Why is perl faster than tcl?
A: Superior designers and developers.
Come on gang, give 'em all a hand! Woop woop.
"Wenzel, Joel [CAR:VS11:EXCH]" wrote:
>
> I'm doing a paper on Tcl and perl and I have an import
> quesition.
>
> Do you know why perl is so much faster then Tcl? I've
> read a lot of things about what slow Tcl down.
> Versions prior to 8.0 did not have a byte-code
> compiler or the capability of storing binary but the
> new Tcl does. I do not know of any other reasons that
> could lead to such a huge cpu time gap.
>
> Does the fact that Tcl can store binary strings mean
> that numbers are now stored in binary. Are
> expressions involving the addition of numbers faster?
------------------------------
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 1150
***************************************