[21888] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4092 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 10 00:06:17 2002

Date: Sat, 9 Nov 2002 21:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 9 Nov 2002     Volume: 10 Number: 4092

Today's topics:
    Re: "each" loop on hash inconsistent? <rick.delaney@rogers.com>
    Re: Can you Simplify My Code? <garry@ifr.zvolve.net>
    Re: change text colour? <mail@eircom.net>
    Re: change text colour? <tony_curtis32@yahoo.com>
    Re: change text colour? (Tad McClellan)
    Re: change text colour? <spam@thecouch.homeip.net>
        Editing Perl scripts in windows environment and running (Peter Manderino)
    Re: Editing Perl scripts in windows environment and run <spam@thecouch.homeip.net>
    Re: Function call inside Quotes? (Jay Tilton)
        help with arrays of arrays <nospam@rostie.net>
    Re: Pause in perl ??? <admin@-NOSPAM-2host.com>
    Re: Pause in perl ??? (Bill Wheaton)
    Re: perl array into sql database <rwh2100@hotmail.com>
    Re: perl array into sql database <krahnj@acm.org>
    Re: significance of 42 for perl, any?!? (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
    Re: Sort multidimensional hash? <vm.mayer@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 10 Nov 2002 04:32:27 GMT
From: Rick Delaney <rick.delaney@rogers.com>
Subject: Re: "each" loop on hash inconsistent?
Message-Id: <m3of8y11ut.fsf@cs839290-a.mtth.phub.net.cable.rogers.com>

Rick Jansen <rja@euronet.nl> writes:

> How would 'scalar keys %ScanHash' perform for very big hashes, like
> a DBM tied hash...? Is there another way to reset the each iterator?

For big hashes that are not tied, it will be quite efficient.
For tied hashes, it will wastefully iterate through all entries.
The only other way to reset the iterator would be to use the method
the tie class provides that can be called as 

    tied(%h)->reset_iterator;

Of course, the class you are using must provide such a method,
which most don't.

-- 
Rick Delaney
rick.delaney@rogers.com


------------------------------

Date: Sun, 10 Nov 2002 01:58:53 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: Can you Simplify My Code?
Message-Id: <slrnasrfas.nl6.garry@zfw.zvolve.net>

On 9 Nov 2002 15:16:03 -0500, yisraelharris <member@mainframeforum.com> wrote:
> The following function strips away trailing blanks. What I'm wondering
> is whether it can be simplified?
> 
> sub trimBlanks { my $string = $_[0]; $string =~ s/ *$//; return
> $string; }


Why are you trimming the empty string from the end?  The * quantifier
will force a match against strings that don't end with a blank.  


> The direction I'm looking for is a one-line statement that says: return
> the parameter sent, only substitute all trailing blanks with nothing. I
> am new to Perl and am wondering if its syntax allows this sort of thing.


Why not just say 

  $string =~ s/ +$//;

instead of 

  trimBlanks $string;

?



> --

That is not a sig dash.  I think you meant "-- \n" instead.  

-- 
Garry Williams


------------------------------

Date: Sat, 9 Nov 2002 23:42:46 -0800
From: "Linux.ie" <mail@eircom.net>
Subject: Re: change text colour?
Message-Id: <aqk2r9$thi$1@dorito.esatclear.ie>

i have a script thats keeps showing up code like the matrix and i want the
text to be green




------------------------------

Date: Sat, 09 Nov 2002 17:50:01 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: change text colour?
Message-Id: <8765v6717a.fsf@limey.hpcc.uh.edu>

>> On Sat, 9 Nov 2002 23:42:46 -0800,
>> "Linux.ie" <mail@eircom.net> said:

> i have a script thats keeps showing up code like the
> matrix and i want the text to be green

And what does this have to do with perl?  If it's a perl
script, show the code, or at least an applicable example
program.



------------------------------

Date: Sat, 9 Nov 2002 18:00:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: change text colour?
Message-Id: <slrnasr8cn.311.tadmc@magna.augustmail.com>

Linux.ie <mail@eircom.net> wrote:

> is it possilbe to change the colour of the text in ms-dos to green ???


This is the Perl newsgroup, ask questions about Perl here.

You should ask MSDOS questions in a newsgroup about MSDOS,
such as:

   comp.os.msdos
   comp.os.msdos.apps
   comp.os.msdos.misc
   comp.os.msdos.programmer


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sat, 09 Nov 2002 20:31:42 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: change text colour?
Message-Id: <3DCDB6FE.1000001@thecouch.homeip.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1



Linux.ie wrote:
| i have a script thats keeps showing up code like the matrix and i want the
| text to be green

You *probably* want to output the correct ANSI string to change the text
color to green.  Keep in mind that for DOS to interpret ANSI strings
correctly, you need the ansi.sys driver to be loaded in memory (I
believe that's done through config.sys, but I'm not 100% sure as it's
been a while since I used DOS)

Check http://search.cpan.org for ANSI modules that could simplify your
job, or google for "ansi colors" to find examples of the exact string
you need to print() out.

Best of luck.


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE9zbb+eS99pGMif6wRAsvoAKDl2TBTLmFF5OPLmI3eQKxU4cCcvACguuew
CDSG0WobQPfQXboV6JSU/4w=
=OhXh
-----END PGP SIGNATURE-----



------------------------------

Date: 9 Nov 2002 16:59:55 -0800
From: peter@manderino.net (Peter Manderino)
Subject: Editing Perl scripts in windows environment and running on linux
Message-Id: <a3702e0e.0211091659.631e065b@posting.google.com>

I am a novice with Perl although I am relitively fluent in other
programming languages.  The problem that I am having is that it
doesn't function when I download a working script from my site and
edit it in windows (I've tried many apps), then upload it again.  I
get a server misconfiguration error message.  This happens even if I
change nothing in the script and simply download, open, save, close,
upload.  It's being run on a linux server and I'm assuming that the
problem exists somewhere in the line feeds.  Does anyone know a
program that I can use in windows to be able to edit an existing Perl
script to be run on a linux server??  Is there another way to address
the problem?  Thanks in advance for your help!


------------------------------

Date: Sat, 09 Nov 2002 20:27:57 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Editing Perl scripts in windows environment and running on linux
Message-Id: <3DCDB61D.4000806@thecouch.homeip.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1



Peter Manderino wrote:
| I am a novice with Perl although I am relitively fluent in other
| programming languages.  The problem that I am having is that it
| doesn't function when I download a working script from my site and
| edit it in windows (I've tried many apps), then upload it again.  I
| get a server misconfiguration error message.  This happens even if I
| change nothing in the script and simply download, open, save, close,
| upload.  It's being run on a linux server and I'm assuming that the
| problem exists somewhere in the line feeds.  Does anyone know a
| program that I can use in windows to be able to edit an existing Perl
| script to be run on a linux server??  Is there another way to address
| the problem?  Thanks in advance for your help!

This is not a perl question, however:

Configure your FTP program to upload/download perl files in ASCII-mode
instead of binary mode.  That will make it automatically translate the
linefeeds for you, preserving your sanity.

Your other option is to download a better editor.  Personally I used
gVIM WIN32 when I used Windows, it's available for free from
http://www.vim.org. Bare in mind that is's based on vim which is in turn
based on "vi", so it's learning curve is pretty steep compared to other
editors.

Best of luck.

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE9zbYceS99pGMif6wRAuxoAKCfeuAs4pfeNmiiBWn/KiypfFWg7gCffMrt
++W6Q8iQ1WzYN8g+whU3wcc=
=57oO
-----END PGP SIGNATURE-----



------------------------------

Date: Sun, 10 Nov 2002 03:58:40 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Function call inside Quotes?
Message-Id: <3dcdd91e.29013734@news.erols.com>

yisraelharris <member@mainframeforum.com> wrote:

: In situations like this:
: 
: my $word = "some text " . length($y) . " more text"; # 1 syntax
: 
: Obviously, if I do the following, I won't be the same as in #1 above:
: 
: my $word = "some text length($y) more text"; # 2 syntax
: 
: My question is: Is there some way to use the #2 syntax, with maybe some
: special character before the call to length, so that perl knows to treat
: it as a function call, as in #1?

Yup.

    my $word = "some text @{[length($y)]} more text";



------------------------------

Date: Sun, 10 Nov 2002 03:36:57 GMT
From: Randy <nospam@rostie.net>
Subject: help with arrays of arrays
Message-Id: <pqjrsugk2sa79ducftppjjknbmjlan645v@4ax.com>

I have a file that is a list of users, the location of a certain file
in their home directory, the word yes or no, and the version of the
file:

$user/t$file/t$safe/t$version

I have made an array of arrays:

while(<FILE>){
        chomp;
        my($user,$file,$safe,$version) = split /\t/;
        $users{$user} = "$file\t$safe\t$version";

What I need to know is how to make a conditional statement, like

while $users{$safe}=no {

do something
}

and if $users{$safe}=yes
ignore and go on to the next line 

This is part of an important project I am working on for work (I don't
have time to do coding when I'm at work,)  so I wold appreciate any
help I can get with this.

Randy


------------------------------

Date: Sat, 09 Nov 2002 17:45:41 -0800
From: "2Host.com - Robert" <admin@-NOSPAM-2host.com>
Subject: Re: Pause in perl ???
Message-Id: <3DCDBA45.935C3A6F@-NOSPAM-2host.com>



"Linux.ie" wrote:
> 
> yea, i got a book, but didnt bother reading it !!!

You should read it, perhaps.

Please also include some small portion of the post you respond to, for
the sake of people being able to know what it's in response to without
further digging through the threads (some of us sort by date).
-- 
Regards,
Robert McGregor - Email: admin@(remove)2host.com. Phone: 530-941-0690
Server admin, support & programing for shared & dedicated web servers
Secure, reliable hosting you expect and deserve! http://www.2host.com


------------------------------

Date: 9 Nov 2002 17:50:33 -0800
From: billwheaton@mindspring.com (Bill Wheaton)
Subject: Re: Pause in perl ???
Message-Id: <b8871133.0211091750.1e02548f@posting.google.com>

"Linux.ie" <mail@eircom.net> wrote in message news:aqjrdd$qk9$1@dorito.esatclear.ie...
> yea, i got a book, but didnt bother reading it !!!
> 
> 
Hmmm... Don't know about a 'pause in perl', but this sure gave me
pause...

So you would rather bother other people instead of bothering to read
it.

And what if the people who you expect answers from never bothered to
read a book, what would be the worth of their answers?

What if the screenwriters of "The Matrix", Larry and Andy Wachowski
didn't bother to research their movie?  Do you think it would have
ever been funded?

Morpheus' ship, for example, the 'Nebuchadnezzar,' is named after the
Babylonian king who lived in the Fifth Century, BC.  Did they simply
pull such a name out of thin air, or do you think they perhaps took
pains to read up on things before writing the story, or perhaps
someone told them?

Would you say that Morpheus was an educated, dedicated man?  Did he
value the raw truth and rage against The Matrix and the big lie it
represented? Without bothering to understand reality, how could he
have ever hoped to reveal the truth and liberate humanity from the
bondage of the machines?

And when NEO said, 'I may not be what Morpheus thinks I am, but if I
don't try to help him, then I'm not even what I think I am' right
before accepting the fact that he was "the One" as foretold by the
prophesy.  You haven't tried even to help yourself young friend, so
what do you think you are?  How do you expect to reveal the truth, by
asking others?  What if they are wrong?  What if they are wrong on
purpose?  How will you know, unless you bother to learn from as many
sources as you can and weigh the possibilities?  And when the world
depends on you, and it will, and you flub it, will you make excuses? 
Or will you have transformed it in some heroic future event?

Someone has to make the future, why not you?  Why make pretty pictures
of things like the falling text they did in the movie.  That's been
done before, its old, its decaying, you are drawing inside the lines
of a coloring book that some grown-up gave you, and you don't even
know it.  How old do you think you have to be to start saving the
world anyway, 18, 21?  Try now bucko.  Use anything that will spark
your imagination.  Falling green text is visually appealing, but has
nothing to do with computer science, its just pretty.  But what if it
leads you to an idea about data compression that could send messages
back and forth to Mars when we land there?  What if it leads you to
imagine a way to make a fake gravitational field without spinning
around like a rock on a string?  Not so pretty then, is it?  Darn
useful, I'd say, you would save peoples lives in space by keeping
their bones from disolving like they do now!  So use fantasy like "The
Matrix" to spark your imagination, not to limit it, and read, by god,
read.

You are given choices over and over again, just like NEO was.  The
blue pill or the red one, accepting his destiny or fading back into
the oblivion of The Matrix.  We all are.  Remember that other guy,
eating steak, fine wine and smokin stogies and selling out? It was all
fake.  He knew it.  He said as much.  The weakling wouldn't deal with
the real thing.  But it was his choice, wasn't it, and the others be
damned, he wouldn't remember them anyway.  The choice -- is yours, 
read the book, or don't, and forever be at the mercy of other people
who's only motive is their own, and not your well being.  Its a
pitiable state to be in.

But let me clue you in. The hard (and fun) work you do by bothering to
read that book, if for only two weeks, will open things up for you
that are better than any fantasy sci-fi flick you'll ever see.  Its
sweeeeeet.

You are 14 years old, already?  Are you always this late?  Better get
moving, time is running out so fast, and others are passing you by. 
They bother to read, of course, maybe, perhaps, oh my, I don't know...
could that be the reason?   Hmmmm... perhaps so Pathagoras!  I don't
think I can be more plain or make it more obvious,
Read.
Read.
Read.

Questions are ok too, of course.  Question Authority (because
questioning idiots is foolish.  Its like trying to teach a pig to
read, as it doesn't work, and annoys the pig.  [kudos to Robert
Heinlein. An author. Of books. With pages. Filled with words and
stuff.  C'mon, I know you've seen one!])

If a man is drowning, and yells for help, and there are things
floating around in the water by his hands, and he doesn't grab at
them, but instead yells at the guy throwing him the rope to throw
harder next time, what is that?

Yep, you got it!  Kinda dumb.  So grab your life preserver and read
it!  It will make sure you are still floating when you get the rope
thrown to you again.

"The Ring of Iron".  Its a marshall arts movie.  Highly recommended.

-bw


------------------------------

Date: Sat, 9 Nov 2002 16:50:14 +1100
From: "Rodney Hunter" <rwh2100@hotmail.com>
Subject: Re: perl array into sql database
Message-Id: <zyhz9.26137$Sr6.758041@ozemail.com.au>


"Adam Hapworth" <hap@mikomi.org> wrote in message
news:a6cb04db.0211081159.6eb73156@posting.google.com...
> "Rodney Hunter" <rwh2100@hotmail.com> wrote in message
news:<BQQy9.25839$Sr6.748171@ozemail.com.au>...
> > newbie using perl CGI script - i have data in an array (passed by POST)
and
> > need to get it into sql database(Oracle)  - here's my attempt that's not
> > working - where's the perl code errors?
> >
> > thanks
> > Rodney Hunter
> >
> > do 'dbi-lib.pl';
> > use CGI ':standard';
> > use DBI;
> > use strict;
> > my $q = new CGI;
> >
> > # get value passed from form
> > my $thisjobno = $q->param('job_no');
> > my @veg_type = $q->param('veg_type');
> > # SQL insert statement
>
> I would do this in a different manor then you have here using DBI,
> which would make $query1 go away
>
> > my $query1 = "insert into ea_veg (job_no, veg_type, veg_status) values
> > ('$thisjobno', '@veg_type', 1)";
> >
> > # Database DBI driver name
> > my $dbname = "DBI:Oracle:";
> >
> >     # Create database handle
> >     my $dbh = DBI->connect($dbname, $user, $passwd);
> >     if (!$dbh) {
> >        showSQLerror("Connecting to the database");
> >        return;
> >     } else {
> >       # set AutoCommit  1 = ON, 0 = OFF (1 is default)
> >       # transaction control *required* here - set OFF
> >       $dbh->{AutoCommit} = 0;
> >     }
> >
> try something like this.
>
> my $sth = $dbh->prepare(q{insert into ea_veg (job_no, veg_type,
> veg_status); values(:job, :type, 1)})||fail "prepare failed";
>
> foreach (@veg_type) {
>     $sth->bind_param(":job",$thisjobno);
>     $sth->bind_param(":type",$_);
>     $sth->execute() || die "insert failed";
> }
> $dbh->commit;
> $dbh->disconnect;
>
> That should be all you would need. Unless I am missing something in
> this logic.
> This was written on the fly so there may be a couple of typos I am
> missing.
>
> Adam
>
> >     # Insert the data fetched
> >     while ((@veg_type) = $sth->fetchrow_array) {
> >     my ($veg_insert);
> >     $veg_insert = run_statement($dbh,$query1,"N");
> >     if ($veg_insert == 1) {
> >         $dbh->rollback;
> >         $dbh->disconnect;
> >         return;
> >     }
>
>
> >     else {
> >         # Commit transaction and disconnect from database
> >         $dbh->commit;
> >         $dbh->disconnect;
> >     }
> >     } # end of fetch while


Woopee! it worked.......thank you - i fixed the typos and the code did the
job needed - how can i fix the one bug remaining as per Apache error log?
 .....

String found where operator expected at c:/apache/htdocs/eaj/eajob2.pl line
76, near "fail "prepare failed""
(Do you need to predeclare fail?)
[Sat Nov 09 16:00:21 2002] [error] syntax error at
c:/apache/htdocs/eaj/eajob2.pl line 76, near "fail "prepare failed""


do 'dbi-lib.pl';
use CGI ':standard';
use DBI;
use strict;
my $q = new CGI;

# get value passed from form
my $thisjobno = $q->param('job_no');
my @veg_type = $q->param('veg_type');

    # DBI Connect for local Personal Oracle8
    # $dbh = DBI->connect('dbi:Oracle:','username','password')
    my $dbname = "DBI:Oracle:";
    my $user = "eaj";
    my $passwd = "eaj";

    # Database DBI driver name
    my $dbname = "DBI:Oracle:";

    # Create database handle
    my $dbh = DBI->connect($dbname, $user, $passwd);
    if (!$dbh) {
       showSQLerror("Connecting to the database");
       return;
    } else {
      # set AutoCommit  1 = ON, 0 = OFF (1 is default)
      # transaction control *required* here - set OFF
      $dbh->{AutoCommit} = 0;
    }

    my $sth = $dbh->prepare(q{insert into ea_veg (job_no, veg_type,
veg_status) values(:job, :type, 1)}) || fail "prepare failed";
    foreach (@veg_type) {
        $sth->bind_param(":job",$thisjobno);
        $sth->bind_param(":type",@veg_type);
        $sth->execute() || die "insert failed";
    }

    $dbh->disconnect;






------------------------------

Date: Sun, 10 Nov 2002 01:17:57 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: perl array into sql database
Message-Id: <3DCDB3B6.4F09721D@acm.org>

Rodney Hunter wrote:
> 
> Woopee! it worked.......thank you - i fixed the typos and the code did the
> job needed - how can i fix the one bug remaining as per Apache error log?
> .....
> 
> String found where operator expected at c:/apache/htdocs/eaj/eajob2.pl line
> 76, near "fail "prepare failed""
> (Do you need to predeclare fail?)
> [Sat Nov 09 16:00:21 2002] [error] syntax error at
> c:/apache/htdocs/eaj/eajob2.pl line 76, near "fail "prepare failed""
> 
> [snip]
> 
>     my $sth = $dbh->prepare(q{insert into ea_veg (job_no, veg_type,
> veg_status) values(:job, :type, 1)}) || fail "prepare failed";
                                          ^^^^^^^^^^^^^^^^^^^^^
Perl is looking for a sub/function named 'fail' and is not finding it. 
Perhaps you you want to use 'die "prepare failed";' instead.


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 09 Nov 2002 23:55:19 +0100
From: mru@users.sourceforge.net (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Subject: Re: significance of 42 for perl, any?!?
Message-Id: <yw1xu1iqxsiw.fsf@gladiusit.e.kth.se>

"Bill Wheaton" <billwheaton@mindspring.com> writes:

> and friends can go jump in a lake for all I care.  Give me zephod

I thought it was zaphod...

> And don't forget where the name for the language translation 'babblefish'

 ... and babel fish.

-- 
Måns Rullgård
mru@users.sf.net


------------------------------

Date: Sat, 09 Nov 2002 19:12:37 -0500
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: Sort multidimensional hash?
Message-Id: <vm.mayer-83542F.19123709112002@news-east.giganews.com>

In article <Xns92C055922F91Dtimstephens@24.69.255.211>,
 T Stephens <user@server.com> wrote:

> I need to sort a multidimensional hash by values, but I can't seem to 
> wrap my head around this. I have sorted hashes by value before, but 
> haven't needed to work with multidimensional ones before.
> 
> For example, if I have the following data:
> 
> Name    	Games    	Goals    	Assists    Points
> Mario    	12    	8    	    	21    	29
> Martin    	13    	9    	    	11    	20
> Alex    	13    	8    	    	11    	19
> Mike    	14    	8    	    	10    	18
> 
> I was planning on setting up the hash structure like so (although it 
> would be loading in from a datafile, and would be looped over):
> 
> $hash{1}{name} = "Mario";
> $hash{1}{games} = 12;
> $hash{1}{goals} = 8;
> $hash{1}{assists} = 21;
> $hash{1}{points} = 29;
> $hash{2}{name} = "Martin";
> $hash{2}{games} = 13;
> $hash{2}{goals} = 9;
> $hash{2}{assists} = 11;
> $hash{2}{points} = 20;
> 
> (and so on)
> 
> Then I need to be able to generate outputs where the data is sorted 
> alphabetically based on almost any criteria and keep the other stats with 
> the corresponding player. Obviously, there would be no point in showing 
> Mario's name with Mike's games, Martin's assists, and Alex's points. 
> 
> I also need to be able to sort the data based on games, goals, assists, 
> and points.
> 
> I've scoured over my Perl books and they do cover sorting hashes on 
> values and multidimensional arrays, but never at the same time.
> 
> Any assistance would be greatly appreciated. Perhaps I'm going about this 
> all wrong...if so let me know that too.
> 
> Tim
> 

Unless the (1,2,3,...) are an intrinsically important number (like a 
  player ID), you have missed the point of hashes...  You are trying
  to create an array using the hash syntax....

You should have something more like:
  $hash{mario}->{games} = 12;
  $hash{mario}->{goals} = 8;
  $hash{mario}->{assists} = 21;
  $hash{mario}->{points} = 29;
  $hash{Martin}->{games} = 13;
  $hash{Martin}->{goals} = 9;
  $hash{Martin}->{assists} = 11;
  $hash{Martin}->{points} = 20;

Or more perlesque:
  $hash{mario} = {games=>12, goals=>8, assists=>21, points=>29};
  $hash{Martin} = {games=>13, goals=>9, assists=>11, points=>20};

Note also that a multidimensional hash doesn't exist as such per se.
  The values of a hash must be a scalar.... but a hash reference is a 
  scalar... thus above, each element of %hash contains an anonymous
  hash reference.

See perldoc perldata and perldoc perlref

On to your actual question... I'll provide an example.

my %hash = ( mario => {games=>12, goals=>8, assists=>21, points=>29},
              Martin => {games=>13, goals=>9, assists=>11, points=>20} );

my @keys = sort { $hash{$a}->{games} <=> $hash{$b}->{games} } keys %hash;

foreach my $key (@keys) {
  # 
  # Do here whatever you want to do with your sorted hash of hashes
  #
}

hth
mike


------------------------------

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 4092
***************************************


home help back first fref pref prev next nref lref last post