Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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
Re: Have a sort of trouble.
by linuxer (Deacon) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-09-21 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls