Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Have a sort of trouble.

by dbmathis (Scribe)
on Feb 02, 2010 at 20:30 UTC ( #821030=perlquestion: print w/ replies, xml ) Need Help??
dbmathis has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Simple one. I am trying to sort these apache files, been away from perl for awhile and not doing something right.

for my $apache_file ( sort { $merge_structure{ apache_log }->{ $a +} cmp $merge_structure{ apache_log }->{ $b } } keys( %{ $merge_struct +ure{ apache_log }\ } ) ) { print "$apache_file\n"; }

This is not right, what am I doing wrong?:

/var/log/httpd/thermofisherhc/access_log /var/log/httpd/thermofisherhc/access_log.1 /var/log/httpd/thermofisherhc/access_log.3 /var/log/httpd/thermofisherhc/access_log.4 /var/log/httpd/thermofisherhc/access_log.2

Comment on Have a sort of trouble.
Select or Download Code
Replies are listed 'Best First'.
Re: Have a sort of trouble.
by linuxer (Curate) on Feb 02, 2010 at 20:44 UTC

    Hi, $a and $b already contain the file path; if you want to sort by the path, just use them:

    What about this?

    for my $apache_file ( sort { $a cmp $b } keys( %{ $merge_structure{ ap +ache_log }\ } ) ) { print "$apache_file\n"; }

    If you don't want to sort by the file path you should tell us, by what you want to sort.

    The file path is the key, you are sorting by the value, whatever that may be...

      Duh, thank you! That's what happens when you don't write perl for a year :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://821030]
Approved by linuxer
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2015-11-29 09:58 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls