[19914] in Perl-Users-Digest
Perl-Users Digest, Issue: 2109 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 11 09:05:37 2001
Date: Sun, 11 Nov 2001 06:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005487509-v10-i2109@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 11 Nov 2001 Volume: 10 Number: 2109
Today's topics:
"WIN32 PERL SCRIPTING, The Administrator's Handbook" fr (Skywarner)
Re: A Newbie's Question <c_clarkson@hotmail.com>
Re: A Newbie's Question (Tad McClellan)
Re: Best language for low self-esteem programmers? <allenmillen@eircom.net>
Re: converting ^M characters to \n (J.B. Moreno)
Re: converting ^M characters to \n <flavell@mail.cern.ch>
Diretory exists? <email@timlauterborn.de>
Re: Diretory exists? <tassilo.parseval@post.rwth-aachen.de>
Re: md5 and hashrefs <andrew@erlenstar.demon.co.uk>
Re: md5 and hashrefs (Randal L. Schwartz)
Re: module to help change login shell (no..chsh is not (Logan Shaw)
Re: module to help change login shell (no..chsh is not (Tad McClellan)
Re: Newbie: Handline CSV files properly <aeropaul@sbcglobal.net>
please help me turn a string into a hash <oahfei@home.com>
Re: please help me turn a string into a hash <Laocoon@eudoramail.com>
Re: please help me turn a string into a hash (Tad McClellan)
Random element from array? (Wiliam Stephens)
Re: Random element from array? (Peter J. Acklam)
Re: Random element from array? <tassilo.parseval@post.rwth-aachen.de>
Re: regular expresion <krahnj@acm.org>
sorting hashes == headaches (Greg Backus)
Re: sorting hashes == headaches <s_grazzini@hotmail.com>
Re: sorting hashes == headaches (Tad McClellan)
Re: web server (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Nov 2001 04:16:55 GMT
From: skywarner@aol.com (Skywarner)
Subject: "WIN32 PERL SCRIPTING, The Administrator's Handbook" from New Riders
Message-Id: <20011110231655.23608.00002540@mb-cf.aol.com>
I picked up this book last year thinking I would start dabbling in the world of
Perl. Of course, I never did. ;-(
This book is in new condition - I never even used it as it turns out.
It sold for $35, but I'd rather see the book get used by someone rather than
collect dust on my shelf. Make me an offer and it's yours (US inquiries only
please) plus shipping costs.
The ISBN is 1-57870-215-1
Thanks in advance!
------------------------------
Date: Sat, 10 Nov 2001 20:14:30 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: A Newbie's Question
Message-Id: <turpsqds6be57e@corp.supernews.com>
James Sullivan" <JJSUSA2001@yahoo.com> wrote:
in message news:9sdm2e$okc$1@slb5.atl.mindspring.net...
: $input = "I am new";
:
: What is the difference between:
:
: @data = split (' ', $input) and
: @data = split(/ /, $input)
:
: What would I get for $data[0], $data[1], $data[2] in both
: cases? Are they any differences?
Yes, there are differences. Read perlfunc->split:
<<
As a special case, specifying a PATTERN of space (' ')
will split on white space just as split with no
arguments does. Thus, split(' ') can be used to emulate
awk's default behavior, whereas split(/ /) will give
you as many null initial fields as there are leading
spaces. A split on /\s+/ is like a split(' ') except
that any leading whitespace produces a null first
field. A split with no arguments really does a
split(' ', $_) internally.
>>
HTH,
Charles K. Clarkson
Clarkson Energy Homes, Inc.
NOTE:
Most of us get quite annoyed with people who ask
questions here without first checking the manuals and
doing some experimentation. The fact that your
subject was: 'A Newbie's Question' instead of
'A question about split' pretty much lost most of the
audience here.
When I get behind I just run a macro to mark
certain messages read. Anything with 'newbie' in the
subject gets axed. I'm certain quite a few here
just killfile such subjects.
The Good is that which leads to health, The Right is that
which leads to peace. Purpose is ours to choose, Meaning is
the story we choose to join. We are all members of Darwin's
family, all kin from the beginning of life. If you value
anything, value other humans, for they are the only help you
will have in times of trouble. The Godless Universe is vast
and wondrous, and more than enough. We have loved the stars
too fondly to be fearful of the night.
------------------------------
Date: Sun, 11 Nov 2001 14:02:52 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: A Newbie's Question
Message-Id: <slrn9usucl.2ti.tadmc@tadmc26.august.net>
Charles K. Clarkson <c_clarkson@hotmail.com> wrote:
>James Sullivan" <JJSUSA2001@yahoo.com> wrote:
> in message news:9sdm2e$okc$1@slb5.atl.mindspring.net...
>: What is the difference between:
>:
>: @data = split (' ', $input) and
>: @data = split(/ /, $input)
>: Are they any differences?
>
> Yes, there are differences. Read perlfunc->split:
>
><<
>As a special case, specifying a PATTERN of space (' ')
The OP has *two* spaces in his patterns, so no special case.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 11 Nov 2001 00:12:19 -0000
From: "Eircom News" <allenmillen@eircom.net>
Subject: Re: Best language for low self-esteem programmers?
Message-Id: <lsjH7.7665$8s4.33137@news.indigo.ie>
> It's not the IQ, but the persistence that makes a programmer.
Could be true. At least I 've seen a couple of examples :)
------------------------------
Date: Sat, 10 Nov 2001 23:27:30 -0500
From: planb@newsreaders.com (J.B. Moreno)
Subject: Re: converting ^M characters to \n
Message-Id: <1f2oiyi.1mtq5lb360ylxN%planb@newsreaders.com>
Alan J. Flavell <flavell@mail.cern.ch> wrote:
> On Nov 10, J.B. Moreno inscribed on the eternal scroll:
>
> > Alan J. Flavell <flavell@mail.cern.ch> wrote:
> >
> > > On Nov 9, Tad McClellan inscribed on the eternal scroll:
> > >
> > > > >> $x =~ tr/\r//d;
> > > >
> > > > the tr/// above removes _all_ CRs regardless of the value in $/
> > >
> > > On the Mac, as I understand it, it'll remove all linefeeds, and leave
> > > any CRs alone.
> >
> > Uhm, did you snip a bit too much above?
>
> Well, I was commenting on what I quoted, and not on what I snipped.
>
> You're referring to this part, right? -
Yeah.
> |>This is more for my education than the original poster's, but
> |>couldn't one accomplish the same thing by the use of chomp()?
> |
> |No.
> |
> |chomp() will remove only a CR at the end of $x, and only if
> |
> | $/ = "\r";
>
> However, this again (mis)identifies the actual control character
> whose value is CR (x0D or \015), with the logical \r. As perldoc
> perlport explains, these are not the same thing on all platforms.
When does \r not equal 0x0d?
> > On the Mac, because of the value in $/, chomp removes 0x0d
>
> Yes
>
> > (LF).
>
> Pardon?
I'm stupid!
> > But tr/\r//d will, as Tad said, remove CRs regardless of the value in $/
>
> No, it'll remove occurrences of \r, whatever they may be on the
> specific platform. I was under the impression that the previous
> discussion had not _meant_ to be platform-specific, but had
> inadvertently become so: I was trying to correct that by pointing to
> the specific example of the Mac.
>
> Ref: http://www.perldoc.com/perl5.6/pod/perlport.html#Newlines
That shows that \n is variable, it doesn't give any examples of \r being
variable, and perlop doesn't say that it is platform specific (in fact
it shows the opposite).
> > (which raises the question as to why there isn't the equivalent for
> > LF's, I know that l and f are both already used for something else, but
> > what about \N?).
>
> Sorry, I don't follow you there.
It's partly my stupidity, and partly a valid (IMO) suggestion.
I.e. \r should (IMO) always be 0x0d and \N should always be 0x0a,
leaving just \n as having a platform specific value.
> > > If it's \015 you're aiming to remove, wouldn't it be better to say so
> > > directly?
> >
> > Are you confusing CRs and LFs here?
>
> Am I?
Nope, I was.
--
JBM
"Your depression will be added to my own" -- Marvin of Borg
------------------------------
Date: Sun, 11 Nov 2001 14:21:46 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: converting ^M characters to \n
Message-Id: <Pine.LNX.4.30.0111111351030.18797-100000@lxplus023.cern.ch>
On Nov 10, J.B. Moreno inscribed on the eternal scroll:
> > Ref: http://www.perldoc.com/perl5.6/pod/perlport.html#Newlines
>
> That shows that \n is variable, it doesn't give any examples of \r being
> variable,
Quote from the above section:
___
/
Some of this may be confusing. Here's a handy reference to the ASCII
CR and LF characters. You can print it out and stick it in
your wallet.
LF == \012 == \x0A == \cJ == ASCII 10
CR == \015 == \x0D == \cM == ASCII 13
| Unix | DOS | Mac |
---------------------------
\n | LF | LF | CR |
\r | CR | CR | LF |
[...]
This doesn't cover EBCDIC-based platforms, however.
> and perlop doesn't say that it is platform specific
\r represents the logical \r function on all platforms. \015
represents the ASCII carriage return character on all platforms. You
don't need to worry whether they're the same or not, as long as you
specify the one that you need. I think that's the point I was trying
to make.
> (in fact it shows the opposite).
I'm reading http://www.perldoc.com/perl5.6/pod/perlop.html
You're referring to this line, I take it?
\r return (CR)
That's unfortunate, but you'll see that it's contradicted (and rightly
so) just a few lines later:
Not all systems read "\r" as ASCII CR and "\n" as ASCII LF. For
example, on a Mac, these are reversed, and on systems
without line terminator, printing "\n" may emit no actual data
> I.e. \r should (IMO) always be 0x0d
As you see, it isn't. If it was, you wouldn't be able to distinguish
between \r and \n on the Mac.
> and \N should always be 0x0a,
> leaving just \n as having a platform specific value.
If you're looking for a non-cryptic way of referring to precisely
the ASCII CR and LF characters, you can use Socket.pm, and export
CR and LF (some of this is also covered in perlport).
I fear that my attempt to achieve a little additional clarification
has spawned off a thread that has only caused extra confusion.
Perhaps the best advice to lurkers is to read the documentation
carefully, trying to avoid any preconceptions which might lead one to
believe that it says something which in fact it doesn't. While there
does seem to be the occasional oddity (you pointed to one above), by
and large it seems to be clear, and more accurate than most usenet
threads on the topic.
all the best
------------------------------
Date: Sun, 11 Nov 2001 12:30:27 +0100
From: "Tim Lauterborn" <email@timlauterborn.de>
Subject: Diretory exists?
Message-Id: <9slngp$85k$1@nets3.rz.RWTH-Aachen.DE>
Hi,
a short question:
What is the easiest way to find out if a directory exists?
Thanks!
Greetings,
Tim
------------------------------
Date: Sun, 11 Nov 2001 13:38:28 +0100
From: Tassilo von Parseval <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Diretory exists?
Message-Id: <3BEE7144.8040402@post.rwth-aachen.de>
Tim Lauterborn wrote:
> Hi,
>
> a short question:
>
> What is the easiest way to find out if a directory exists?
'perldoc -f -X'
'-d' in particular.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 10 Nov 2001 23:33:50 +0000
From: Andrew Gierth <andrew@erlenstar.demon.co.uk>
Subject: Re: md5 and hashrefs
Message-Id: <87snbmtd41.fsf@erlenstar.demon.co.uk>
>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:
Bart> The sillyness of the idea hides in the fact that the string ->
Bart> md5 mapping is not unique. Even though the chance of a
Bart> collision is very small, it is not unthinkable. After all, md5
Bart> only produces a 16 byte string from whatever string you feed
Bart> it.
there are no known pairs of strings that hash to the same md5 values.
Of course such strings necessarily exist, but none have been found; if
you generate one message-id per nanosecond, then even allowing for the
birthday paradox it takes you something like 600 years to get an even
chance of one or more collisions.
It's quite common for Usenet software, for example, to convert all
message-ids to MD5 hashes on input and use only the hash internally;
this has the huge advantage that the hashes are fixed length, whereas
the ids themselves are hugely variable.
--
Andrew.
------------------------------
Date: 11 Nov 2001 04:57:37 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: md5 and hashrefs
Message-Id: <m1lmhdfose.fsf@halfdome.holdit.com>
>>>>> "AG" == Andrew Gierth <andrew@erlenstar.demon.co.uk> writes:
AG> there are no known pairs of strings that hash to the same md5 values.
AG> Of course such strings necessarily exist, but none have been found; if
AG> you generate one message-id per nanosecond, then even allowing for the
AG> birthday paradox it takes you something like 600 years to get an even
AG> chance of one or more collisions.
The word on the street is that one of the many-CPAN-module Perl
hackers actually found two images "in the wild" that MD5'ed to the
same string. I've not been able to confirm this yet (this was
third-hand on some IRC chat).
--
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: 10 Nov 2001 17:19:37 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: module to help change login shell (no..chsh is not available on solaris...)
Message-Id: <9skcm9$8a7$1@charity.cs.utexas.edu>
In article <kdarutggbmbko8btss4ajugeqbh25jotij@4ax.com>, jeff <hk63a> wrote:
>Solaris does not have chsh functionality any longer (bastards..)
>so, i am trying to write a setuid (*GASP*) script to enable users to
>change their passwords and gecos info without bothering me anymore!!
:
:
>I'd rather not rewrite the whole /etc/passwd file each time manually
>using "open" and such..thats just waiting to crash the system.
So call /usr/bin/passwd and have it make the changes to /etc/passwd.
Actually, it seems like you should be able to get sudo to do this for
you, but from looking at the sudoers manual page, I can't find a way to
tell it to allow a user to run "passwd" only with their own login name
as an argument. OTOH, the version of sudo I'm looking at isn't the
latest, so maybe there is a way. And even if there isn't, it's a minor
modification to make, and it would solve the problem for you.
You might also try posting to comp.unix.solaris and asking there.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: Sun, 11 Nov 2001 01:07:17 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: module to help change login shell (no..chsh is not available on solaris...)
Message-Id: <slrn9urgtu.rvu.tadmc@tadmc26.august.net>
jeff <none@nothere.please.net> wrote:
>X-No-Archive: yes
What is the point of using that when you use a fake address
and only first name anyway?
Nobody is going to know who you are, so why not let the
thread have a "head"?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 11 Nov 2001 02:21:23 GMT
From: "Paul Johnson" <aeropaul@sbcglobal.net>
Subject: Re: Newbie: Handline CSV files properly
Message-Id: <DglH7.2760$Af.230296671@newssvr14.news.prodigy.com>
> Did you check http://search.cpan.org/search?mode=module&query=csv already?
No, but I did indicate "Newbie" in the subject line.
Thanks for the link.
Paul
------------------------------
Date: Sun, 11 Nov 2001 07:39:28 GMT
From: "Antoine Daccache" <oahfei@home.com>
Subject: please help me turn a string into a hash
Message-Id: <QWpH7.149551$5h5.63637426@news3.rdc2.on.home.com>
I got a assignment due for my programming class wednesday and I can't figure
this out, I been on it for 3 hours reading the book, and reading the
teacher's note...nothing, someone out there please help me out
$departmentinfo = "A,Accounting;IS,Info
Systems;MGT,Management;PSP,Pepsi;Coke,Coca Cola;RA,;Win,Windows;SPN,";
I got this...I want to put this into a hash using the first value as a key,
and the 2nd as the data..example
%hash1 = key value
A Accounting
IS Info Systems
etc
if it's still unclear, here's what he says
----
1- Create a string variable that contains at least 8 department code - name
pairs with the delimeter ';' between each pair and the delimeter ',' between
the code and corresponding name (example: "A,Accounting;IS,Info
Systems;MGT,Management........."). Include at least two codes that do not
currently have a value (ex. CCC,;)
2- Convert the above string to a hash using department code as the key and
department name as the value
----
TIA,
Antoine Daccache
------------------------------
Date: Sun, 11 Nov 2001 11:34:40 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: please help me turn a string into a hash
Message-Id: <Xns915675CACC6EBLaocooneudoramailcom@62.153.159.134>
*snip*
> $departmentinfo = "A,Accounting;IS,Info
> Systems;MGT,Management;PSP,Pepsi;Coke,Coca Cola;RA,;Win,Windows;SPN,";
>
> I got this...I want to put this into a hash using the first value as a
> key, and the 2nd as the data..example
>
> %hash1 = key value
> A Accounting
> IS Info Systems
> etc
*snip*
example :
while ($departmentinfo =~ /(\w+),(\w*)/g) {
$hash{$1} = "$2"
}
Hope this helps u..
Lao
------------------------------
Date: Sun, 11 Nov 2001 14:02:49 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: please help me turn a string into a hash
Message-Id: <slrn9ustod.2ti.tadmc@tadmc26.august.net>
Antoine Daccache <oahfei@home.com> wrote:
>$departmentinfo = "A,Accounting;IS,Info
>Systems;MGT,Management;PSP,Pepsi;Coke,Coca Cola;RA,;Win,Windows;SPN,";
>
>I got this...I want to put this into a hash using the first value as a key,
>and the 2nd as the data..example
>2- Convert the above string to a hash using department code as the key and
>department name as the value
perldoc -f split
loop over split /;/, split on commas within the loop.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 11 Nov 2001 02:13:03 -0800
From: wil@fbagroup.co.uk (Wiliam Stephens)
Subject: Random element from array?
Message-Id: <39e3e00a.0111110213.3f44662b@posting.google.com>
I've got an array containing 5 elements. I want to be able to pick one
of these elements at random.
Has anyone got a snippet of code that will pick an element from an
array at random?
Thanks
Wil Stephens
------------------------------
Date: 11 Nov 2001 11:32:24 +0100
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Random element from array?
Message-Id: <lmhdoax3.fsf@online.no>
wil@fbagroup.co.uk (Wiliam Stephens) wrote:
> I've got an array containing 5 elements. I want to be able to
> pick one of these elements at random.
>
> Has anyone got a snippet of code that will pick an element from
> an array at random?
For an array of arbitrary length, use
$element = $array[int rand @array];
In this case, you can replace "@array" by "5".
In any case, the int() isn't really necessary.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Sun, 11 Nov 2001 11:32:27 +0100
From: Tassilo von Parseval <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Random element from array?
Message-Id: <3BEE53BB.8070703@post.rwth-aachen.de>
Wiliam Stephens wrote:
> I've got an array containing 5 elements. I want to be able to pick one
> of these elements at random.
>
> Has anyone got a snippet of code that will pick an element from an
> array at random?
Well, use the rand() function:
my @a = (1, 2, 3, 4);
print $a[int rand @a];
'int rand @a' means the script should take a random-number between 0 and
the number of elements in @a and truncate the floating part. That is,
it will pick either 0, 1, 2 or 3.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 11 Nov 2001 02:47:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regular expresion
Message-Id: <3BEDE6CB.4E26478E@acm.org>
Steven Edwards wrote:
>
> On Sat, 10 Nov 2001 15:19:34 GMT, tadmc@augustmail.com (Tad McClellan)
> wrote:
>
> >
> >[ Please DO NOT send stealth Cc's. It annoys people. Thank you. ]
>
> It wasn't a Bcc; I hit the wrong button to reply and sent an email
> reply by accident.
>
> >The quotes are not "special". They do not need any escaping!
> >
> >
> >>Can you
> >>give another version?
> >
> >
> >Uhh, yes:
> >
> > $t =~ s/^.*"([^"]+)".*/$1/;
> >
> >:-)
>
> I wasn't trying to be a smartass -- it was a serious question. I was
> not aware that quotes did not need to be escaped. I assumed that
> since they needed to be escaped in strings:
>
> $t = "Hello \"World\"";
>
> that they also needed escaping in regular expressions. Thanks for
> letting me know that. :-)
They only need to be escaped in strings that use them to delimit the
string.
$t = "Hello \"World\""; # "s need to be backwacked
$t = qq(Hello "World"); # The same string without escapes
$t = qq/Hello "World"/; # The same string without escapes
$t =~ s"^.*\"([^\"]+)\".*"$1"; # "s need to be backwacked
$t =~ s/^.*"([^"]+)".*/$1/; # The same regex without escapes
$t =~ s#^.*"([^"]+)".*#$1#; # The same regex without escapes
John
--
use Perl;
program
fulfillment
------------------------------
Date: 11 Nov 2001 00:06:56 -0800
From: gdbackus@yahoo.com (Greg Backus)
Subject: sorting hashes == headaches
Message-Id: <33a7d0f5.0111110006.67cc17c3@posting.google.com>
OK - I'm sure that there's a way to sort a hash by its values which
will prompt me to kick myself inthe seat after having had pulled my
hair out tring to figure out a way, so I will be a bald Perl programmer
with a sore butt - assuming I can get some help!
I have a frequency hash - the keys are IP addresses the values are the #
of times they appear in files in a particular directory. I want to sort
it for output so that those address which appear most frequently will be
displayed first.
Been trying to put the keys and the values into two seperate lists but
sorting the IP address list would be meaningless...
Somebody tell me the builtin I am missing...
thanks
Greg
------------------------------
Date: Sun, 11 Nov 2001 08:25:24 GMT
From: "Steve Grazzini" <s_grazzini@hotmail.com>
Subject: Re: sorting hashes == headaches
Message-Id: <UBqH7.65963$XA5.12310791@typhoon.nyc.rr.com>
"Greg Backus" <gdbackus@yahoo.com> wrote in message
news:33a7d0f5.0111110006.67cc17c3@posting.google.com...
> OK - I'm sure that there's a way to sort a hash by its values which
> will prompt me to kick myself inthe seat
[..]
>
> Somebody tell me the builtin I am missing...
> thanks
> Greg
You still have to sort the keys...
my %hash = (
'192.168.1.1' => 8,
'192.168.1.2' => 4,
'192.168.1.11' => 19
);
my @sorted_keys =
sort { $hash{$b} <=> $hash{$a} } keys %hash;
for my $key (@sorted_keys) {
print "$key was accessed $hash{$key} times.\n";
}
Check faq4 or (of all places ;) perldoc -f sort.
-Steve
------------------------------
Date: Sun, 11 Nov 2001 14:02:50 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: sorting hashes == headaches
Message-Id: <slrn9usu10.2ti.tadmc@tadmc26.august.net>
Greg Backus <gdbackus@yahoo.com> wrote:
>OK - I'm sure that there's a way to sort a hash by its values which
Yes. You might even guess that this Question is Asked Frequently...
>will prompt me to kick myself inthe seat after having had pulled my
>hair out tring to figure out a way, so I will be a bald Perl programmer
>with a sore butt - assuming I can get some help!
You deserve a measure of pain for missing the answer that is
already installed on your own hard drive :-)
>Somebody tell me the builtin I am missing...
^^^^^^^^^^^^^^^^^^^^
It appears to be "perldoc -q" :-)
perldoc -q sort
"How do I sort a hash (optionally by value instead of key)?"
You are expected to check the Perl FAQ *before* posting to
the Perl newsgroup.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 11 Nov 2001 14:02:51 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: web server
Message-Id: <slrn9usu77.2ti.tadmc@tadmc26.august.net>
cool dude <control153@yahoo.com> wrote:
>I am not sure if this is the correct message board to post this :
This is not a "message board". This is a Usenet newsgroup.
Web servers have nothing to do with Perl, so this is surely not
the correct newsgroup for your question.
>does anyone know how to start a web server from scratch ??
>i apologize if this is not the proper place to post this but please let
>me know where to go and if you guys have any helpful links .
There are a whole boatload of comp.infosystems.www.* newsgroups
were web-stuff is discussed.
Maybe:
comp.infosystems.www.servers.unix
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 2109
***************************************