Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

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 sunlight beams...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2018-02-24 16:22 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (310 votes). Check out past polls.