[8746] in Perl-Users-Digest
Perl-Users Digest, Issue: 2363 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 19 11:08:47 1998
Date: Sun, 19 Apr 98 08:00:38 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 19 Apr 1998 Volume: 8 Number: 2363
Today's topics:
Re: EASY QUESTION: Replacing a line in a textfile <gwynne@utkux.utk.edu>
Get day out of 19/04/1998 13:24:41 <red_danger@hotmail.com>
Re: Help, I'm going Perl-bald! (Jonathan Stowe)
Re: How to skip HTML codes? <bmb@ginger.libs.uga.edu>
Re: keys in hashs (Bart Lateur)
New Website <m.ubl@elmshorn.netsurf.de>
Password changing under Solaris (Dave Haywood)
Re: Password changing under Solaris <sneaker@earthling.net>
Re: Piping to Awk Problem (Jonathan Stowe)
Re: Project question and gripe about (Re: Snobby news g <merlyn@stonehenge.com>
Q. Modules <mindmore@mindless.com>
Re: RFC: Adding Commands in Filehandles... <repost> (Tanstaafl)
Re: RFC: Adding Commands in Filehandles... <repost> (Tom Mornini)
Re: RMS should be invited to O'Reilly's "Free Software nathanh@chirp.com.au
Re: RMS should be invited to O'Reilly's "Free Software nathanh@chirp.com.au
Sorting an associative array. (Han Yiguang (Hang))
Re: Sorting an associative array. (Andrew M. Langmead)
Re: Sorting Arrays to Numbers <lr@hpl.hp.com>
The Basic Network <flanker@sonnet.ru>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 19 Apr 1998 10:44:52 -0400
From: "Bob Gwynne" <gwynne@utkux.utk.edu>
Subject: Re: EASY QUESTION: Replacing a line in a textfile
Message-Id: <6hd2o4$1s9$1@gaia.ns.utk.edu>
Abigail wrote in message <6hbq5d$6ur$4@client3.news.psi.net>...
>Miguel Barrientos (boliviaweb@prodigy.net) wrote on MDCXCI September
>MCMXCIII in <URL: news:6hb0b4$2sq0$1@newssvr04-int.news.prodigy.com>:
>++ I realize this is a very basic question, but I'm just starting.
>
>Then it is a good start to read the manuals and the FAQ.
>Alternatively, you can buy a good book. See www.perl.com
>for some book reviews.
>
>++ How do I replace a line in a text file?
>
>That is a vague question, with many different answers, depending
>what exactly you want. The manual will help you find the right
>approach.
>
Now those are good answers. Congratulations should go out to Abigail. The
"use diamonds" answer in a previous post was funny (in an inside way), but
could have been followed by an explanation of the diamond operator that
would make the info useful to the poster. Maybe we'll have to change the
drawing on the cover of Web Client Programming with Perl from Abigail to
Mother Teresa. Naawwww!
Bob Gwynne
Speech Comm
University of Tennessee
------------------------------
Date: Sun, 19 Apr 1998 13:33:49 +0200
From: Red Danger <red_danger@hotmail.com>
Subject: Get day out of 19/04/1998 13:24:41
Message-Id: <3539E11C.A06F8D29@hotmail.com>
Hello,
Mebay a silly question, but i want to know how i can get the day of a
function who return time like 19/04/1998 13:24:41. How can I get the
info it is sunday????? This because I make a checklist writen in Perl
witch CGI and on monday there is an other ckecklist than on Sunday ect..
So i have to know witch checklist i must sent to an user.
Thank you,
Henk
------------------------------
Date: Sun, 19 Apr 1998 12:24:58 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Help, I'm going Perl-bald!
Message-Id: <3539e0d4.6398158@news.btinternet.com>
On Sun, 19 Apr 1998 02:18:19 -0600, msbzdragn@hotmail.com wrote:
>Newsgroups: comp.lang.perl.misc
>Subject: Help, I'm going Perl-bald!
>Date: Sun, 19 Apr 1998 02:18:19 -0600
<etc>
You might find
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
A useful read if you want people to read your posts here.
>
>I'm going bald prematurely, and all because I've just become a newbie... ;) I
>
Thats a good excuse. Do we have a new category here "The Slap Head
Newbie".
>just started playing around with Perl and CGI for a project I am trying to do
>at work, and I'm completely baffled...
Eh,oh
>
>I've got a web server (Sambar, http://www.sambar.com) running on Windows NT
>Server 4.0, using the included Perl executables - and CGI works fine, so long
>as I use the included scripts.
<snip>
Sweet FA to do with Perl but any reason you dont use IIS and the
"standard" Perl available as a binary distribution from the usual
place? This Sambar thing has been creeping in over the last couple of
weeks from (as far as I am concerned) previous obscurity.
>I don't get any error message, in fact I don't get anything at all on the
>scripts that I am trying to install - the browser just sits and eventually
>times out. Where am I going wrong?
>
It would be nice to see one of the scripts before making any comment -
I dont think there is anyone called Doris frequenting the group
currently.
A couple of pointers:
Use the module CGI.pm - this along with its excellent documentation
will take the pain out of doing CGI with Perl. If you havent got it
with your setup it is available from www.perl.com/CPAN (but see
comment above - the "standard" distribution comes with it)
use the -w switch with perl to give you debugging help (you may have
to do something with the server to achieve this - but thats out of
scope) and use this code from Randal Schwartz (thanks to
tim@maroney.org who reminded us ) at the top of your code to get some
diagnostic output to your browser:
## death handler, presumes no output yet
$SIG{'__DIE__'} = $SIG{'__WARN__'} = sub {
my $error = shift;
chomp $error;
$error =~ s/[<&>]/"&#".ord($&).";"/ge; # entity escape;
print "Content-type: text/html\n\n[$error]\n";
exit 0;
};
Run your scripts at the command line to check they are working (using
CGI.pm will greatly assist you in doing this)
Read the FAQ , Read the FAQ, Read the FAQ (Both Perl and CGI - see
link below)
>
>I'll be happy to give any information that might help track down where I've
>tripped over and landed on my newbie-face - I am quite sure I am just doing
Credit card numbers always help
>something embarrassingly obvious wrong, but there's the joys of teaching
>yourself this sorta stuff I guess...
>
Its just unfortunate that around here people seem to discover this at
a point of no return in some
project/homework/plan-for-world-domination...
/J\
Jonathan Stowe
See the MetaFaq at http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm
------------------------------
Date: Sun, 19 Apr 1998 09:43:16 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: How to skip HTML codes?
Message-Id: <Pine.A41.3.96.980419092813.61556A-100000@ginger.libs.uga.edu>
term: 'the faq'
definition: the faq for 'this list'
where: in the note you received after your first post to this list
Abigail could have done what I did, and that was to simply ignore your
question, since it's in the faq. Instead, she took the time to point you
in the right direction. Maybe I should learn to be more helpful.
Of course, I don't expect you'll thank me, either :-)
Brad Baxter
UGA
On Sat, 18 Apr 1998, Dan Baker wrote:
> Abigail wrote:
> > That's answered in the faq.
> ------------
> appreciate it even more if you could be more specific when refering
> people to FAQs.
> Dan
------------------------------
Date: Sun, 19 Apr 1998 11:02:15 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: keys in hashs
Message-Id: <353cd66f.4229774@news.tornado.be>
Andrew M. Langmead wrote:
>Since the version of perl you used seems to have a copyright
>notification from four years ago, isn't it much more likely that this
>is a bug that has been fixed?
Could this "bug fixing" be expanded, to include this as well? (example
adapted from the HTML:: entities module):
%entity = ( 'times' => 'x' , # 'times' is a Perl keyword
);
So, could Perl's behaviour be "fixed" so that the quotes around 'times'
may be dropped? Or has this be done already?
If not, the habit of dropping the quotes around hash keys in such hash
definitions will be very unsafe, with regard to future keywords
expansion.
Bart.
------------------------------
Date: Sun, 19 Apr 1998 13:31:34 +0100
From: Malte Ubl <m.ubl@elmshorn.netsurf.de>
Subject: New Website
Message-Id: <3539EEA6.5784@elmshorn.netsurf.de>
Hello,
I just released a very interesting website concerning Perl-Scripts.
You'll find there new scripts (Access-Counter, Statistics) that
are very easy to install and use which I developed for the website
http://www.io.com/~icc.
Go to http://elmshorn.netsurf.de/~m.ubl ! You won't be disappointed !
I'll soon release some kind of "CGI-Script-Office" with a guided
wizzard-style installation, so that you dont have to change any
of the variables in the scripts.
Who can offer me cgi-enabled web-space for free?
mailto:m.ubl@elmshorn.netsurf.de
Thank you,
Malte Ubl
--
\ Malte Ubl \
\ mailto:m.ubl@elmshorn.netsurf.de \
\ http://elmshorn.netsurf.de/~m.ubl \
\ http://www.io.com/~icc \
------------------------------
Date: Sun, 19 Apr 1998 12:05:55 GMT
From: D.Haywood@btinternet.com (Dave Haywood)
Subject: Password changing under Solaris
Message-Id: <6hcpa4$qeu$1@uranium.btinternet.com>
Hi,
Problem : I want to use Perl to change other users passwords (as root). The
standard Solaris 2.5.1 passwd command does not allow re-direction of input so
I can't easily use it. I want something like:
./chpw <userid> <newpassword>
I think these are the possible solutions:
a) write a C program to change the password (yeuck! I don't know how)
b) Use the Expect package (yeuck! Expect and TCL just for this?)
c) Use the Perl built-in getpw* routines (I don't understand how to do
this)
d) Use a fabled built-in Expect module in Perl (I can't find this)
Can anyone help with:
a) a solution based on (c) or (d) above
b) details of whether (d) exists and where it is
c) example code
I have serached the CPAN, FAQ, Solaris mailing lists etc.
Thanks!
Dave Haywood.
------------------------------
Date: Sun, 19 Apr 1998 13:28:55 GMT
From: Bill 'Sneex' Jones <sneaker@earthling.net>
Subject: Re: Password changing under Solaris
Message-Id: <3539FA7D.7498CDCD@earthling.net>
Dave Haywood wrote:
> Hi,
>
> Problem : I want to use Perl to change other users passwords (as root). The
> standard Solaris 2.5.1 passwd command does not allow re-direction of input so
> I can't easily use it. I want something like:
>
For various reasons, security and otherwise, passwddoes not allow capturing of
the /dev/tty or /dev/pts without
some gyrations. People like Don Libes (who wrote Expect/TCL)
and Austin Schutz (who wrote Expect.pm for Perl) have performed
those gyrations for us :-)
>
> d) Use a fabled built-in Expect module in Perl (I can't find this)
Not fabled, but findable under http://www.perl.com/CPAN/modules/by-authors/Lookup
Austin Shutz :-)
>
>
> Can anyone help with:
> a) a solution based on (c) or (d) above
> b) details of whether (d) exists and where it is
> c) example code
>
> I have serached the CPAN, FAQ, Solaris mailing lists etc.
Hmmm, I have made a WebPass system (of two programs,Perl & Expect based) which do
what you are looking for
under Solaris (I use them everyday on an E3000 and Ultra-1)
As far as Expect.pm goes, I am in-process of writing
the WebPass system to only use Expect.pm for Perl instead
of Expect/TCL...
Expect.pm and the resulting WebPass system will
require IO::Tty, IO::STTY, Expect.pm, and Perl 5.004_4
Your question is one many others have asked, and you
COULD perform the magic with crypt using a gyration like -
$Salt = "$Schars[int(rand($Ssize))]$Schars[int(rand($Ssize))]";
(The above is from an old hack I found in a Perl book over
a year ago. Problem is, it isn't very nice to newbies and you
can destroy your /etc/passwd and /etc/shadow files...)
__________________________
Bill Jones...............|
Sneaker's Nest...........|
Chasecreek Systemhouse...|
------------------------------
Date: Sun, 19 Apr 1998 12:24:54 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Piping to Awk Problem
Message-Id: <3539ca13.1358954@news.btinternet.com>
On Sat, 18 Apr 1998 21:34:17 -0800, Tom Claydon <tclaydon@troika.net>
wrote:
<snip>
>
>The problem I'm having is that I want to take that information (stored
>in $time) and pipe that to awk.
There are two solutions I would suggest:
#!/home/tclaydon/perl -w
$ENV{TERM}="vt100";
$basedir = "/home/tclaydon/tsscan/";
$tslist = $basedir . "test";
open(TS, $tslist) || die "Cant open input file - $!";
open(AWK,"|awk -f awkprog.awk") || die "Cant run AWK - $!";
#Always but always test for failure of open and such like
while (<TS>) {
# you dont need the assignment
chomp; #You did mean chomp didnt you
# This assuming you have only your time column
# your actual file with 8 columns will use split() or somesuch.
s/://g;
$time = $_;
print AWK "$time\n";
}
close( AWK) || die "probable error with AWK - $! ";
close TS;
__END__
You're opening AWK within your Perl program rather than using an
external pipe.
The preferred alternative for the more discerning perl programmer is
to do with AWK altogether. As the glossary in the Camel book puts it
awk
Descriptive editing term - short for "awkward".
Also coincidentally refers to a venerable text
processing language from which Perl derived
some of its ideas.
Now in recognition of its use in some quarters as an awk++ (eech),
Perl has shipped as long as I have known it with a utility a2p which
will take your AWK script and spit out the corresponding (slightly
less than idiomatic under certain circumstances) Perl code. This
should be considered a starting point rather than an end in itself.
You can now amend the generated Perl to open the file and then perform
the substitution on the time column. Without seeing your AWK script I
couldnt say what you would need to do but in a simple case (adding the
third column and printing out the total) you might get:
#!perl
eval 'exec c:/develop/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
# this emulates #! processing on NIH machines.
# (remove #! line above if indigestible)
eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
# process any FOO=bar switches
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
$total = 0;
while (<>) {
($Fld1,$Fld2,$Fld3) = split(' ', $_, 9999);
$total = $total + $Fld3;
}
print $total;
For readability you may want to change the variable names ;-}
/J\
>--
Jonathan Stowe
See the MetaFaq at http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm
------------------------------
Date: Sun, 19 Apr 1998 14:29:05 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
To: Mark Constable <markc@renta.net>
Subject: Re: Project question and gripe about (Re: Snobby news group)
Message-Id: <8cemytansj.fsf@gadget.cscaper.com>
>>>>> "Mark" == Mark Constable <markc@renta.net> writes:
Mark> Totally agree. I cannot believe some of these people here
Mark> have got the hide to reply to some newbies plea for help
Mark> with some antagonistic "get a clue" type post... without
Mark> directly offering any help !!
I read nearly every article in comp.lang.perl.misc and
comp.lang.perl.modules. I see three types of responses:
1) an answer to the question
2) a request to go look at manual X or FAQ Y or Dejanews Z for the answer,
rather than having us retype it
3) a request to take the question to a more appropriate group (usually
ciwac)
and then I also see a lot of the following meta-responses:
A) bitching about posts that aren't one of 1-2-3 above
B) responses from people that do 1-2-3 above saying that there is no #4
Well, this is another "B" response. I challenge you to find a post
that isn't one of 1-2-3 above. Please. For my sake, so that we know
what you're bitching about, SPECIFICALLY.
<sigh>
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 135 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Sun, 19 Apr 1998 15:25:27 +0300
From: Fain <mindmore@mindless.com>
Subject: Q. Modules
Message-Id: <3539ED37.C08DD36@mindless.com>
Anyone that knows of a simple script that uses a module (a simple
module).. could you please send it to me.
I am trying to learn how to use modules. Anything you have that could
help please pass it on.
Thanks
- Nathan Fain
mindmore@mindless.com
------------------------------
Date: Sun, 19 Apr 1998 11:03:22 GMT
From: Tanstaafl@geocities.com (Tanstaafl)
Subject: Re: RFC: Adding Commands in Filehandles... <repost>
Message-Id: <353cd77a.2907729@news.xs4all.nl>
With great joy and love, Tom Phoenix <rootbeer@teleport.com> wrote:
Hello Tom Phoenix,
>On Tue, 14 Apr 1998, Tanstaafl wrote:
>
>> I'm currently reading the book on Perl 5 and I'm learning it
>> from scratch, so please forgive my ignorance.=20
>
>Everyone, even Larry, learned Perl from scratch. (Of course, Larry =
already
>knew a few dozen programming languages when he started learning Perl...
I know bits and pieces for lots of programming languages, but
Perl is slowly becoming my favorite.
>> I've copied and run many scripts that were in the book,
>
>Which book? (If it's relevant.)
"Teach yourself CGI programming with Perl in a week." Not that
I think I can learn it in a week, but I'm on Day 3 (Sixth chapter) and
it's only been a month. This is suppossed to be my ump into Perl...
>> but I wanted to see if I could create something from scratch. This is =
my
>> first attempt, please correct any mistakes. I don't understand what's
>> going wrong...=20
>
>> Basically I wanted to write a standard script I could add to any
>> program that I created that would handle any commands I used.=20
>
>Huh? I don't understand that. But it sounds as if you might want to make=
a
>module rather than a "standard script".
Oops, yeah a module
>> To this purpose and because I haven't gotten very far in the book I'm
>> trying it with file handles. (IOW, with $#ARGV.)=20
>
>Oops. $#ARGV isn't a file handle. It's one smaller than the number of
>command line arguments passed to your program (by default).
It's says command line file handle, maybe be cause of the text
of the script that added I thught it was pure file handle. Although I
read bugtraq and I saw it refered to as file handler. That's why my
posting there was called "Handler Mapped File Extensions Bug"...
>> #! /usr/local/bin/perl
>
>If your code doesn't work for you, ask Perl to help by warning about
>anything suspicious it sees. To do that, use the -w invocation argument =
on
>the #! line. (Also, some systems don't allow a space between the #! and
>the path to perl.)
I just recieved the FAQ, thanks.
>> if ($#ARGV < 1)
>> {
>> print << "end_tag";
>> # Checks for at least one filehandle
>>=20
>> end_tag
>
>Now, you know that that's not a comment in there, right?
I didn't know that, this book is teaching me naughty stuff or
what?
>> exit (1);
>> }
>>=20
>> # Now it should call the correct sub-routine to handle the
>> # command.
>>=20
>> if ($ARGV[0] =3D "?")
>
>You don't usually want an assignment within an if clause. You may wish =
to
>use one of the modules which are designed to handle command-line
>arguments.=20
Could you point nme in the correct direction...
>> open ($ARGV[1])
>
>Do you know what open does with one argument? Also, you should always
>check the return value of open - although, maybe, you thought you were
>doing so.
This is for opening a new file, correct. (Otherwise I use the
<< and < commands...?)
>You should probably read the Llama book before going further. Hope this
>helps!
ISBN please... (What's this thing with Llama's???)
blaze your trail!
--
David Dune
=46orgive my questions, I'm a newbie.
Unsolicited commercial email read for $500 per message.
------------------------------
Date: Sun, 19 Apr 1998 14:41:51 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: Re: RFC: Adding Commands in Filehandles... <repost>
Message-Id: <tmorniniEro0tr.BLv@netcom.com>
Tanstaafl (Tanstaafl@geocities.com) wrote:
: >> if ($#ARGV < 1)
: >> {
: >> print << "end_tag";
: >> # Checks for at least one filehandle
: >>=20
: >> end_tag
: >
: >Now, you know that that's not a comment in there, right?
: I didn't know that, this book is teaching me naughty stuff or
: what?
Everything between << "end_tag" and end_tag is called a here document. It
is just like a double-quoted string, carriage returns and all. It has
nothing to do with files, file handles, or opening.
: >> if ($ARGV[0] =3D "?")
: >
: >You don't usually want an assignment within an if clause. You may wish =
: to
: >use one of the modules which are designed to handle command-line
: >arguments.=20
: Could you point nme in the correct direction...
What he means is that = is assignment, == is equality operator. In an if
statement, you'd usually use ==, which is numeric equality, or eq, which
is string equality. What is the 3D there for?
As for modules to do what you have in mind, how about GetOpt? It's part
of the standard distribution.
: >> open ($ARGV[1])
: >
: >Do you know what open does with one argument? Also, you should always
: >check the return value of open - although, maybe, you thought you were
: >doing so.
: This is for opening a new file, correct. (Otherwise I use the
: << and < commands...?)
No...
open FILEHANDLE,"/path/to/filename";
opens for reading, as does
open FILEHANDLE,"</path/to/filename";
To write (normally the first step in a new file,
open FILEHANDLE,">/path/to/filename";
: >You should probably read the Llama book before going further. Hope this
: >helps!
: ISBN please... (What's this thing with Llama's???)
O'Rielly and Associates' books usually have animals on the cover. The Llama
book is "Learning Perl" and is a great place to start. ISBN 1-56592-042-2
I'd be somewhat amazed if a major bookstore didn't have this book in stock.
-- Tom Mornini
-- InfoMania
------------------------------
Date: 16 Apr 1998 19:29:46 +1000
From: nathanh@chirp.com.au
Subject: Re: RMS should be invited to O'Reilly's "Free Software Summit"
Message-Id: <m3iuoam7w5.fsf@stoli.spirits.org.au>
tzs@halcyon.com (Tim Smith) writes:
> (1) Those other users are free to get it and use it. If, say, Microsoft
> takes a copy of my public domain code and puts it in something
> proprietary, it in no way lessens the freedom of the public domain
> code. People often point out when arguing in favor of free software
> that copying software does not harm anyone, because it does not take
> away from the original. That exact same point applies when
> something free is used in something non-free: it does not take away
> from the original. (Well, if the proprietary program is so much
> better than the free program, it kills user interest in the free
> program, and so the developers give up, then the proprietary program
> could be said to have harmed the free program, but if the free
> program is that easily killed, then who cares?)
>
> (2) If by having something free of mine in the proprietary code, the
> proprietary product is improved, I have helped the users of that
> proprietary product.
You have allowed commercial software to continue to exist, when in
all probability the free software would have eventually caught and
surpassed the commercial equivalents. You have allowed an inferior
parasitic form of software to survive when it should have died.
Supposedly "free" licenses that allow commercial parasites to take
without giving are unfairly slanting the playing field away from a
free software society towards a commercial software society. It is
not conducive to the goal of software being free.
You are right that it doesn't (directly) affect the freedom of the
individual package, but non-GPL alike licenses hurt the freedom of
software itself. You owe it to yourself to contribute code under a
license that promotes further contributions.
BSD licenses don't do this, thus they are inferior to the GPL.
--
Modern computers have advanced to the point where they are extremely
intuitive, though obviously you have to spend a lot of time learning
how to use them first.
------------------------------
Date: 16 Apr 1998 09:46:58 +1000
From: nathanh@chirp.com.au
Subject: Re: RMS should be invited to O'Reilly's "Free Software Summit"
Message-Id: <m3k98qmyvh.fsf@stoli.spirits.org.au>
tzs@halcyon.com (Tim Smith) writes:
> With there now being at least five reasonable ways one could release free
> software (public domain, GPL, MPL, BSD/X (I'll count these as one even
> though many people find the differences significant), and Artistic), people
> should really consider very carefully the license they use. They should
> not automatically use GPL just because, say, they develop on Linux and most
> of the stuff on Linux is GPL'ed, nor should they choose BSD just because
> they happen to be using FreeBSD.
You should choose GPL because none of the other license guarantees
that the software you write today will continue to be developed as
free software tomorrow.
Your other licenses allow free code to be hoarded. The GPL takes a
firm *positive* stance against hoarding by requiring that GPL code
must never be distributed non-freely.
None of the other licenses guarantee this, therefore all the other
licenses are inferior.
It's a difference between being generous, and being responsible. A
free software developer who doesn't release code under the GPL has
not guaranteed the software's continuing freedom.
--
Without loss of generality, substitute "GPL" with any license that
guarantees similar freedom from hoarding.
------------------------------
Date: Sun, 19 Apr 1998 11:04:46 GMT
From: hangyk@singnet.com.sg (Han Yiguang (Hang))
Subject: Sorting an associative array.
Message-Id: <3539d938.6649433@news.singnet.com.sg>
Hi,
I am stuck with the problem of sorting an associative array.
Can a Perl guru help?
My associative array contains something like...
Key, Value
C, 192
D, 67
A, 129
Z, 16
J, 28
B, 183
L, 67
foreach $i (sort keys %aalist)
{
print "$aalist{$i}\n";
}
But this gives me a sort on the keys. Even if I use this...
foreach $i (sort %aalist)
{
print "$aalist{$i}\n";
}
It didn't help. Anyway to sort on the values? And in numerical
manner?
Thanks!
Thank you.
Jason
------------------------------
Date: Sun, 19 Apr 1998 14:14:05 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Sorting an associative array.
Message-Id: <ErnzJH.L9D@world.std.com>
hangyk@singnet.com.sg (Han Yiguang (Hang)) writes:
>It didn't help. Anyway to sort on the values? And in numerical
>manner?
Have you seen the entry in the FAQ "How do I sort a hash (optionally
by value instead of key)?" <URL:http://www.perl.com/CPAN/doc/
manual/html/pod/perlfaq4/How_do_I_sort_a_hash_optionaly.html>
It may have some information that would be of interest to you. (and
probably of very little interest to most everyone else, otherwise it
wouldn't be in the FAQ.)
for $i ( sort { $aalist{$a} <=> $aalist{$b} } keys %aalist ) {
print "$aalist{$i}\n"";
}
--
Andrew Langmead
------------------------------
Date: Sun, 19 Apr 1998 07:01:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: Craig Berry <cberry@cinenet.net>
Subject: Re: Sorting Arrays to Numbers
Message-Id: <353A03AB.80BBFFF3@hpl.hp.com>
Craig Berry wrote:
>
> Reni Tschannen (r.tsch@gmx.net) wrote:
...
> : ... so it's evident it's not sorted to the arithmetical values of the
> : numbers. What I want is a descending order in this format:
> :
> : Erde.jpg=102
> : Dachs.jpg=76
> : Bach.jpg=50
> : Berg3.jpg=23
>
> What you want here is a Schwartzian Transform. As a newbie, you may not
> 'get' this immediately, but figuring this out will move you significantly
> toward Perl enlightenment.
>
> @jpg_new = map { $_->[0] }
> sort { $a->[1] <=> $b->[1] }
> map { [ $_, (/=(\d+)/, $1) ] }
> @jpgs;
>
> Note that this goes directly from your unsorted jpgs list into the sorted
> version, all in one (complex) operation, and retaining exactly the
> original elements with formatting quirks intact.
>
> ---------------------------------------------------------------------
> | Craig Berry - cberry@cinenet.net
> --*-- Home Page: http://www.cinenet.net/users/cberry/home.html
> | Member of The HTML Writers Guild: http://www.hwg.org/
> "Every man and every woman is a star."
Good answer, but...
Two problems here:
1. He asked for a descending sort. So:
sort { $b->[1] <=> $a->[1] }
2. Your map works, but by coincidence. As this is a list context,
there are actually three elements in each anonymous array, and you are
sorting on the second element, which *is* the extracted digit string.
So:
map { [ $_, /=(\d+)/ ] }
To help him grok this all, you might also have aimed him at the
definitive work on this subject,
http://www.perl.com/CPAN-local/doc/FMTEYEWTK/sort.html .
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: 19 Apr 1998 10:27:59 GMT
From: "Michael Yevdokimov" <flanker@sonnet.ru>
Subject: The Basic Network
Message-Id: <01bd6af1$5d18a240$0f02000a@castle.sonnet.ru>
Hello Everyone!
You are welcome to visit the web site of The Basic Network:
http://www.basicnet.sonnet.ru
* Free Banners Exchange for Programmers - http://www.basicnet.sonnet.ru/Ad
* PWORLD Magazine - http://www.basicnet.sonnet.ru/Pworld
* Resources for Developers - http://www.basicnet.sonnet.ru/Res
* Ask our programmers - http://www.basicnet.sonnet.ru/Conferen
* more...
--
Best wishes,
Michael Yevdokimov,
International Coordinator
of The Basic Network
--------------------------------------------
http://basicnet.sonnet.ru
http://basicnet.home.ml.org
Email: flanker@sonnet.ru
BasicNet: 777:5020/0
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2363
**************************************