[24340] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6529 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 6 11:06:22 2004

Date: Thu, 6 May 2004 08:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 6 May 2004     Volume: 10 Number: 6529

Today's topics:
        ANNOUNCE: AFS Perl API 2.2.2 released <nog@MPA-Garching.MPG.DE>
    Re: Books online???? axel@white-eagle.co.uk
    Re: Books online???? (Randal L. Schwartz)
    Re: Books online???? axel@white-eagle.co.uk
    Re: Books online???? (GreenLight)
    Re: Directory sorted in chronological order <mdudley@king-cart.com>
    Re: Directory sorted in chronological order <mdudley@king-cart.com>
    Re: for loop <glex_nospam@qwest.invalid>
    Re: for loop <tore@aursand.no>
    Re: for loop <remorse@partners.org>
        Formmail Question (replace "nospam" with "com")
    Re: Formmail Question <noreply@gunnar.cc>
    Re: free source authentication script axel@white-eagle.co.uk
    Re: newbie regexp question <supaklailert@yahoo.com>
    Re: newbie regexp question <raisin@delete-this-trash.mts.net>
        perl require <mail@mail.com>
    Re: perl require (Anno Siegel)
    Re: perl require <mail@mail.com>
        perl script to remove entire tags!? <nigel@nothing.com>
    Re: perl script to remove entire tags!? <jurgenex@hotmail.com>
    Re: Sort Hash o Hash accordint to two keys <matternc@comcast.net>
    Re: Sort Hash o Hash accordint to two keys (Malik Yousef)
    Re: Sort Hash o Hash accordint to two keys <remorse@partners.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 6 May 2004 11:13:38 GMT
From: Norbert Gruener <nog@MPA-Garching.MPG.DE>
Subject: ANNOUNCE: AFS Perl API 2.2.2 released
Message-Id: <HxAIF4.1x93@zorch.sf-bay.org>


AFS Perl API Version 2.2.2
    I am pleased to announce the AFS Perl API 2.2.2 release

    The AFS module bundle is a dynamically loadable extension to
    Perl. It gives the AFS user and administrator access to many of
    the AFS programming APIs, allowing you to make these calls
    directly from Perl, rather then processing the output of a
    command. The AFS module bundle is a thin layer above the low-level
    AFS APIs.

Where To Get It
    The version 2.2.2 is now available at

        http://www.MPA-Garching.MPG.de/~nog/perl/AFS-2.2.2.tar.gz
        http://www.cpan.org/authors/id/N/NO/NOG/AFS-2.2.2.tar.gz

    This release should work on all UNIX/Linux platforms which have
    AFS API interfaces and the appropriate C compilation environment.

User visible changes in this release
    - improved test drivers
    - improved Make scripts
      including checks for Perl "unthreaded" version


For more information about the current state of the AFS Perl API,
check my "AFS Perl API Kwiki" site at:

        http://www.mpa-garching.mpg.de/kwiki/nog/afsperl/


Share and Enjoy!

Norbert
-- 
Ceterum censeo          | PGP encrypted mail preferred.
Redmond esse delendam.  | PGP Key at www.MPA-Garching.MPG.de/~nog/




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

Date: Thu, 06 May 2004 10:24:01 GMT
From: axel@white-eagle.co.uk
Subject: Re: Books online????
Message-Id: <5nomc.360$Nf6.111@nurse.blueyonder.net>

Robert <catcher@linuxmail.org> wrote:
> That makes no sense at all. So maybe my post should have been harsher. 
> Basically what you are saying is "don't bother me". The reasons you give 
> for not notifying O'Reilly are rediculous. You should have just said "I 
> don't want to be bothered." and left it at that. Instead you give 
> non-sensical reasons for not doing the *right* thing. I can only hope in 
> real life you are a more ethical person.

How many copyright violations do you think there are out there on the
web? Do you seriously think that everytime someone stumbles across what
he knows is one or suspects might be one, that he should immediately
report it (to whom?)?

Axel




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

Date: Thu, 06 May 2004 10:41:11 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Books online????
Message-Id: <5ec564848dfa4f16a831e932e8010223@news.teranews.com>

>>>>> "axel" == axel  <axel@white-eagle.co.uk> writes:

axel> How many copyright violations do you think there are out there on the
axel> web? Do you seriously think that everytime someone stumbles across what
axel> he knows is one or suspects might be one, that he should immediately
axel> report it (to whom?)?

How often do you have to be consistent with every process in your life?
All we're talking about here is reporting O'Reilly books online to
infringement@ora.com.  What you do in the rest of your day is up to you.

print "Just another Perl hacker,"; 

-- 
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: Thu, 06 May 2004 13:19:58 GMT
From: axel@white-eagle.co.uk
Subject: Re: Books online????
Message-Id: <2Yqmc.8366$4m5.76@front-1.news.blueyonder.co.uk>

Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> axel> How many copyright violations do you think there are out there on the
> axel> web? Do you seriously think that everytime someone stumbles across what
> axel> he knows is one or suspects might be one, that he should immediately
> axel> report it (to whom?)?

> How often do you have to be consistent with every process in your life?
> All we're talking about here is reporting O'Reilly books online to
> infringement@ora.com.  What you do in the rest of your day is up to you.

Well, I can say I have never come across one online except for the odd
chapter when I browse the O'Reilly site :)

Although I have seen other things online which I suspect may be
violations of copyright law, but who am I to judge whether a press
cutting or image violates the copyright law of some other country?

Axel




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

Date: 6 May 2004 07:54:03 -0700
From: google@milbaugh.com (GreenLight)
Subject: Re: Books online????
Message-Id: <c4b60ce1.0405060654.7873bd0d@posting.google.com>

"bxb7668" <bxb7668@somewhere.nocom> wrote in message news:<Hx5Bp0.Dn1@news.boeing.com>...

> stuck or didn't know where to find the answer. I have a firm rule on
> questions: "There is no such thing as a stupid question. Just stupid
> answers."
> 

Well, I completely disagree. I have heard a lot of questions that I
can only characterize as "stupid". I have never quite grasped how that
little saying came about...


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

Date: Thu, 06 May 2004 10:24:11 -0400
From: Marshall Dudley <mdudley@king-cart.com>
Subject: Re: Directory sorted in chronological order
Message-Id: <409A4A8B.CE8B3F32@king-cart.com>

Tore Aursand wrote:

> On Wed, 05 May 2004 16:24:00 -0600, Jim Cochrane wrote:
> > my @dir =
> >       map { $_->[0] }
> >       sort { $a->[1] <=> $b->[1] }
> >       map { [$_, -M] } readdir(DIR);
>
> I have never spoken bad about ST before, but isn't this overkill in this
> given situation?  Wouldn't the (untested) code below create a list of the
> files in chronological order?
>
>   my @dir = sort { -M $a <=> -M $b } readdir( DIR );

Thank you very much. This worked beautifully and was exactly what I needed.
Efficiency is not that important, the code would be called rarely, and even
then the directory size is normally not that large.

Thanks,

Marshall



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

Date: Thu, 06 May 2004 10:41:22 -0400
From: Marshall Dudley <mdudley@king-cart.com>
Subject: Re: Directory sorted in chronological order
Message-Id: <409A4E92.A863FBE7@king-cart.com>

Here are the stats for the two with a directory with just under 2,000 files in it:

# time perl testtime1.pl
number of files = 1864
0.046u 0.092s 0:00.13 100.0%    16+381k 0+0io 0pf+0w

# time perl testtime2.pl
number of files = 1864
0.021u 0.014s 0:00.03 100.0%    20+840k 0+0io 0pf+0w

And this is the code for testtime1.pl:

opendir (DIR,"./");
my @dir = sort { -M $a <=> -M $b } readdir( DIR );
close DIR;
my $number_of_files = scalar @dir;
print "number of files = $number_of_files\n";

and for testtime2.pl:

opendir (DIR, "./");
my @dir =
        map { $_->[0] }
        sort { $a->[1] <=> $b->[1] }
        map { [$_, -M] } readdir(DIR);

closedir DIR;

my $number_of_files = scalar @dir;
print "number of files = $number_of_files\n";


Marshall


Uri Guttman wrote:

> >>>>> "SH" == Sam Holden <sholden@flexal.cs.usyd.edu.au> writes:
>
>   SH> On Thu, 06 May 2004 01:23:35 +0200, Tore Aursand <tore@aursand.no> wrote:
>   >> On Wed, 05 May 2004 16:24:00 -0600, Jim Cochrane wrote:
>   >>> my @dir =
>   >>> map { $_->[0] }
>   >>> sort { $a->[1] <=> $b->[1] }
>   >>> map { [$_, -M] } readdir(DIR);
>   >>
>   >> my @dir = sort { -M $a <=> -M $b } readdir( DIR );
>   >>
>   SH> The ST is an optimisation technique and as such is never neccesary.
>
>   SH> However, this case is one where it is almost certainly useful. -M
>   SH> results in a stat system call and system calls are slow, even
>   SH> worse it may require waiting dor a disk read which is even slower
>   SH> (though filesystem level caching should prevent that happening
>   SH> more than once on machines without much other disk access
>   SH> happening). To make matters even worse stat calls need to access
>   SH> the file based on its name, which is linear in the number of files
>   SH> in the directory.
>
>   SH> So each -M in the sort comparison function is O(N) (assuming a crappy
>   SH> filesystem with such linear access - which is normal) with possibly a
>   SH> large constant (hitting the disk). The sort comparison function is
>   SH> called O(N*logN) times and hence we have O(N*N*logN).
>
>   SH> The ST version gives us an O(1) comparison function and hence O(N*logN)
>   SH> for the sort, which is *much* better.
>
> all of the sort optimization techniques (ST, GRT and orcish) do
> that. the real savings is in converting any O( N log N ) work to O(N)
> work (running -M on each file only once). you have to count the work of
> -M as a constant in general. it may be O(N) when scanning the dir but
> that will be cached in ram for sure as it will be hit often. the inodes
> could be scattered around (or clustered on some file systems) but that
> could be more disk or other complex access. disk accesses outweigh any
> linear scan in ram times so ignore the file name search time.
>
>   SH> This is the first example I've seen where the ST actually reduces the
>   SH> runtime complexity of the sort by more than a constant factor - since
>   SH> it's the first time I've noticed a sort where the comparison function
>   SH> isn't O(1) in terms of the size of the list being sorted.
>
> your analysis is slightly off IMO. you need to count inode accesses as
> the main work and that is still O(N log N) and with caching who knows?
> factoring out the -M to O(N) time is the win.
>
> and the GRT factors out even more by removing the callback code itself
> and using the internal cmp function.
>
> and a perfect time to plug my soon to be released Sort::Maker
> module. here is how it would be used to solve this:
>
>         use Sort::Maker ;
>
>         my $M_sorter = make_sorter( 'ST', number => '-M' ) ;
>
>         my @sorted = $M_sorter->( readdir(DIR) ) ;
>
> or with the GRT for more speed:
>
>         my $M_sorter = make_sorter( 'GRT',
>                         number => {
>                                 code => '-M',
>                                 unsigned_float => 1,
>                         }
>         ) ;
>
>         my @sorted = $M_sorter->( readdir(DIR) ) ;
>
> if anyone wants to get a beta of this module i can get you the url. it
> works for all 4 sort styles and has decent pod. it need many more tests,
> benchmarks and examples in pod. if you want to be a beta tester and
> provide any feedback, email me. my goal is to release it before
> yapc::buffalo as i am giving a talk on it there.
>
> uri
>
> --
> Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org



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

Date: Thu, 06 May 2004 07:02:01 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: for loop
Message-Id: <_Opmc.4$4p5.2156@news.uswest.net>

Fatted wrote:

> my @array = qw(first second third fourth);
> my $i;
> 
> for($i = 0, @array, $i++)
> {
>     print $_."\n";
> }

Others have pointed out the ',', error. Just wanted to mention that 
you'll find the following more common, in perl:

foreach my $i ( 0 .. $#array )
{
	print "$i $array[$i]\n";
}


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

Date: Thu, 06 May 2004 14:20:07 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: for loop
Message-Id: <pan.2004.05.06.12.16.12.831818@aursand.no>

On Thu, 06 May 2004 07:02:01 -0500, J. Gleixner wrote:
> Others have pointed out the ',', error. Just wanted to mention that 
> you'll find the following more common, in perl:
> 
> foreach my $i ( 0 .. $#array )
> {
> 	print "$i $array[$i]\n";
> }

Or - shorter;

  print "$_ $array[$_]\n" for ( 0..$#array );


-- 
Tore Aursand <tore@aursand.no>
"What we see depends mainly on what we look for." (Sir John Lubbock)


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

Date: Thu, 06 May 2004 09:42:28 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: for loop
Message-Id: <remorse-E78818.09422806052004@plato.harvard.edu>

In article <409a0400$1@news.kcl.ac.uk>,
 Mark Clements <mark.clements@kcl.ac.uk> wrote:

> You have the syntax for "for" incorrect (OK - it's "correct", but isn't what 
> you want to do 
> here). Try
> 
> for(my $i = 0 ; $i < $#array ; $i++){
> 
> note ; instead of ,
> also, @array replaced by $i < $#array. Unless you are modifying @array (not a 
> good variable 
> name, by the way), then it will always be true in this case.

Shouldn't that be either:

   $i <= $#array

or

   $i < @array

(or, and I know I will be castigated to kingdom come for this, but my 
preferred version is:

   $i < scalar(@array)

)

Ricky

-- 
Pukku


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

Date: Thu, 06 May 2004 13:48:01 GMT
From: Jim Tome <jtome@demicooper.nospam (replace "nospam" with "com")>
Subject: Formmail Question
Message-Id: <200405060848011575%jtome@demicoopernospamreplacenospamwithcom>

Hello, I'm not much of a Perl programmer (I usually just adapt a canned 
formmail script!), but I have a situation where I need to route 
information from an HTML contact form to different people (via having 
the form results e-mailed via the aforementioned formmail) depending on 
which checkbox in a form is selected.

Just to make it a little more difficult, the form needs to process to 
more than one person if more than one checkbox is selected (e.g. if 
box1 then mailto person1, if box1 and box2 then mailto person1 and 
person2).

Can anyone help me with altering the formmail scriot to include the if 
statements that determine the recipient? Also, I'm not sure where in 
the canned script the changes should go.

Any help?

Either post here or e-mail me directly.

Thanks!



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

Date: Thu, 06 May 2004 16:00:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Formmail Question
Message-Id: <2fuv19F2jv2eU1@uni-berlin.de>

Jim Tome wrote:
> Can anyone help me with altering the formmail scriot to include the
> if statements that determine the recipient?

You have come to the wrong place for at least one, maybe two, reasons.

1) This group is for discussing the Perl programming language. Perl
job requests should be posted elsewhere, e.g. at http://jobs.perl.org/

2) There are many scripts named "formmail". If the one you are talking
about would be Matt Wright's formmail, people here are generally
disinclined to have anything to do with it, since it's considered bad
Perl code.

On the other hand, if you make the formmail script at
http://nms-cgi.sourceforge.net/scripts.shtml the starting point, learn
some basic Perl, and make a serious attempt to make the mod yourself,
you'll most likely get the necessary help here (if needed).

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 06 May 2004 12:21:51 GMT
From: axel@white-eagle.co.uk
Subject: Re: free source authentication script
Message-Id: <z5qmc.672$7l7.662@nurse.blueyonder.net>

Tore Aursand <tore@aursand.no> wrote:
> Murphy's law:  What can go wrong, will go wrong (at least that's the law
> translated directly from Norwegian, my primary language).

Or O'Connor's addendum: "Murphy was an optimist".

Axel




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

Date: Thu, 6 May 2004 21:00:05 +0700
From: "Supak Lailert" <supaklailert@yahoo.com>
Subject: Re: newbie regexp question
Message-Id: <1083852011.624496@lemon.yipintsoi.com>

"Zachary Turner" <zturner_NOSPAM_0826@hotmail.com> wrote in message
news:Hafmc.67091$NR5.54148@fe1.texas.rr.com...
> Why doesn't this work like I expect it to?
>
> if ($string =~ /$pattern/) {
>     ...
> }

It should work. I tried it and it worked on my machine, too. Can you
provide sample value of $string and $pattern?

Supak





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

Date: Thu, 6 May 2004 09:42:26 -0500
From: Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: newbie regexp question
Message-Id: <MPG.1b040ac8f40e63e989814@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <Hafmc.67091$NR5.54148@fe1.texas.rr.com>, zturner_NOSPAM_0826
@hotmail.com says...
> Why doesn't this work like I expect it to?
> 
> if ($string =~ /$pattern/) {
>     ...
> }
> 
> Basically I built the pattern on the fly, so I can't hardcode it.  My guess
> is that it's not interpolating the variable.  So how do I get it to do this?
> 
> Thanks


What is it doing ? (you should have given more details)



use warnings;
use strict;

my ( $string , $pattern );

if ( $string =~ m/${pattern}/ ) {
    # found it
}


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

Date: Thu, 6 May 2004 11:57:21 +0100
From: "bob" <mail@mail.com>
Subject: perl require
Message-Id: <njWdnaXCoucLhwfdSa8jmA@karoo.co.uk>

Is it possible to dynamically change the location of a module
i.e.
require Plugins::Wetherbys::Generate::GenerateXML;
Plugins::Wetherbys::Generate::GenerateXML->import('help');

works fine

but ideally

i would like

require Plugins::$VAR::Generate::GenerateXML;
Plugins::Wetherbys::$VAR::GenerateXML->import('help');

I have looked through the FAQs and couldn't find anything.
I know you can do require $VAR;

Cheers




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

Date: 6 May 2004 11:23:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl require
Message-Id: <c7d76p$a3u$1@mamenchi.zrz.TU-Berlin.DE>

bob <mail@mail.com> wrote in comp.lang.perl.misc:
> Is it possible to dynamically change the location of a module
> i.e.
> require Plugins::Wetherbys::Generate::GenerateXML;
> Plugins::Wetherbys::Generate::GenerateXML->import('help');
> 
> works fine
> 
> but ideally
> 
> i would like
> 
> require Plugins::$VAR::Generate::GenerateXML;
> Plugins::Wetherbys::$VAR::GenerateXML->import('help');

Your original example has the same string twice.  These two lines
can never be the same string, no matter what $VAR contains.  I'll
assume you meant

    require Plugins::$VAR::Generate::GenerateXML;
    Plugins::$VAR::Generate::GenerateXML->import( 'help');

> I have looked through the FAQs and couldn't find anything.
> I know you can do require $VAR;

You can even do "require EXPRESSION", but the problem is that "require"
in that form expects a file name and the method call needs a class name.
You won't be able to do this with a single variable, but this should work
(untested):

    my $VAR = 'Wetherbys';
    my $class = "Plugins::$VAR::Generate::GenerateXML";
    ( my $module = $class) =~ s{::}{/}g; # File::Spec would be better
    $module .= '.pm';                    # File::Spec would be better
    require $module;
    $class->import('help');

This mess may be best stuffed into a sub and taken out of sight.

Anno


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

Date: Thu, 6 May 2004 12:23:40 +0100
From: "bob" <mail@mail.com>
Subject: Re: perl require
Message-Id: <cvudnQLSV5xcvQfdSa8jmw@karoo.co.uk>

cheers ill give it a try.
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:c7d76p$a3u$1@mamenchi.zrz.TU-Berlin.DE...
> bob <mail@mail.com> wrote in comp.lang.perl.misc:
> > Is it possible to dynamically change the location of a module
> > i.e.
> > require Plugins::Wetherbys::Generate::GenerateXML;
> > Plugins::Wetherbys::Generate::GenerateXML->import('help');
> >
> > works fine
> >
> > but ideally
> >
> > i would like
> >
> > require Plugins::$VAR::Generate::GenerateXML;
> > Plugins::Wetherbys::$VAR::GenerateXML->import('help');
>
> Your original example has the same string twice.  These two lines
> can never be the same string, no matter what $VAR contains.  I'll
> assume you meant
>
>     require Plugins::$VAR::Generate::GenerateXML;
>     Plugins::$VAR::Generate::GenerateXML->import( 'help');
>
> > I have looked through the FAQs and couldn't find anything.
> > I know you can do require $VAR;
>
> You can even do "require EXPRESSION", but the problem is that "require"
> in that form expects a file name and the method call needs a class name.
> You won't be able to do this with a single variable, but this should work
> (untested):
>
>     my $VAR = 'Wetherbys';
>     my $class = "Plugins::$VAR::Generate::GenerateXML";
>     ( my $module = $class) =~ s{::}{/}g; # File::Spec would be better
>     $module .= '.pm';                    # File::Spec would be better
>     require $module;
>     $class->import('help');
>
> This mess may be best stuffed into a sub and taken out of sight.
>
> Anno




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

Date: Thu, 6 May 2004 19:08:36 +0930
From: "Nigel" <nigel@nothing.com>
Subject: perl script to remove entire tags!?
Message-Id: <409a079c$1_1@news.adelaide.pipenetworks.com>

hello

with perl is there a way to delete entire <tags> text </tags> from a file?

the apache vhost.conf has many sites but when one is deleted, they need to
be deleted. ServerName is always unique though. is there a perl script that
can delete multiline expressions?

<VirtualHost *>
 ServerName testdomain12.com
 ServerAdmin admin@testdomain12.com
 ErrorLog /home/sites/site61/log_errorlog
 CustomLog /home/sites/site61/log_customlog common
 DocumentRoot /home/sites/site61/www
 RewriteEngine on
 <Directory /home/sites/site61/www>
  Options Indexes
   #ExecCGI
  AllowOverride AuthConfig Limit
  Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>

thanks.




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

Date: Thu, 06 May 2004 10:37:15 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl script to remove entire tags!?
Message-Id: <vzomc.39313$sK3.2093@nwrddc03.gnilink.net>

Nigel wrote:
> with perl is there a way to delete entire <tags> text </tags> from a
> file?

Seems you are looking for XML::Parser or maybe HTML::Parser?

jue




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

Date: Thu, 06 May 2004 06:27:10 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Sort Hash o Hash accordint to two keys
Message-Id: <2-6dnbqlpLFjjwfd4p2dnA@comcast.com>

Malik Yousef wrote:

> Hi
> I have the fellwoing hash structure:
> %allresults{hdrnam}{WinPosition}
>                    
> 
> First i would like to sort the hash according to the key "hdrname" and
> then to sort according to the WinPosition which is with numeric value.

You can't sort a hash; hashes are unordered.
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: 6 May 2004 06:22:44 -0700
From: yousef@pcbi.upenn.edu (Malik Yousef)
Subject: Re: Sort Hash o Hash accordint to two keys
Message-Id: <a70ad489.0405060522.5965a5a3@posting.google.com>

Let me make it simple
I have the hash keys with two information, the name and the window
position separated by <->, for example:
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->1492
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->1531
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->1795
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->23
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->2918
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->2921
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->2925
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->3304
Bc007713_220356885-220369973_intron15_hsa-mir-153-1<->3305

I want to sort this keys according to the name and the window
position, so
*<->23 should be as the first element, so how could one sort according
to the first part ($1)<->($2) and the second part at the same time.
Please send your reply also to yousef@pcbi.upenn.edu



Uri Guttman <uri@stemsystems.com> wrote in message news:<x74qqu42x1.fsf@mail.sysarch.com>...
> >>>>> "EB" == Eric Bohlman <ebohlman@earthlink.net> writes:
> 
>   EB> yousef@pcbi.upenn.edu (Malik Yousef) wrote in 
>   EB> news:a70ad489.0405051742.309c9cb6@posting.google.com:
> 
>   >> Hi
>   >> I have the fellwoing hash structure:
>   >> %allresults{hdrnam}{WinPosition}
>   >> 
>   >> 
>   >> First i would like to sort the hash according to the key "hdrname" and
>   >> then to sort according to the WinPosition which is with numeric value.
> 
>   EB> "perldoc -q sort" will bring up a very helpful tutorial entitled
>   EB> "How do I sort an array by (anything)?"  Now of course you say you
>   EB> want to sort a *hash* rather than an array, but that's not really
>   EB> possible.  You probably want to build an array of indices into the
>   EB> hash and then sort that array; the code in the FAQ will help you
>   EB> with that.
>  
> huh?? there is even an faq on how to sort a hash (by key or value).
> 
> uri


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

Date: Thu, 06 May 2004 09:27:13 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: Sort Hash o Hash accordint to two keys
Message-Id: <remorse-592475.09271306052004@plato.harvard.edu>

In article <c7crt4$1kr$1@mamenchi.zrz.TU-Berlin.DE>,
 anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> Malik Yousef <yousef@pcbi.upenn.edu> wrote in comp.lang.perl.misc:
> > Hi
> > I have the fellwoing hash structure:
> > %allresults{hdrnam}{WinPosition}
> 
> That's not Perl.
> 
> > First i would like to sort the hash according to the key "hdrname" and
> > then to sort according to the WinPosition which is with numeric value.
> 
> Your specification makes no sense, specifically the part beginning
> with "and then...".
> 
> "Sorting a hash" is a loose way of saying "sorting the keys of a hash".
> So you want to sort the keys, alphabetically presumably.  But hash
> keys are unique, so the sorting order is completely specified.  There
> is no way to bring in a secondary sort order.

Perhaps the OP wants something like this:

   #!/usr/bin/perl
   use strict;
   use warnings;

   my %allresults = ( ... );

   foreach my $header_name (sort keys %allresults) {
      foreach my $win_position (sort keys %{$allresults{$header_name}}) {
         print "${header_name}, ${win_position}\n";
      }
   }

   __END__

Ricky

-- 
Pukku


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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