Hi,
I'm trying to do something a bit more complex now:
my @sorted_phrases = sort { $b->{sort_number} <=> $a->{sort_number
+}, $b->{count} <=> $a->{count} }
values %$strings;
..instead of just:
my @sorted_phrases = sort { $b->{count} <=> $a->{count} }
values %$strings;
Basically, what I need to do - is :
1) Sort by the value "count" as they were done before
2) If the 2nd array element has a value of "0" for "count", then it will order them by sort_number thereafter.
I've tried all kinda things - including this messy bit of code - but I can't seem to get it working :(
my @sorted_phrases_2;
# my $i = 0;
foreach (my $i = 0; $i <= $#sorted_phrases; $i++) {
local $_ = $sorted_phrases[$i];
if ($i == 1) {
print "BLA BLA XXX - \"$_->{count}\" " . Dumper($_);
if ($_->{count} < 1) {
my $chosen_id_now = $sorted_phrases[0]->{sort_number}
++ 1;
print qq|<br />Current sort was: $sorted_phrases[0]->{
+sort_number} , and new one is $chosen_id_now <br />|;
foreach my $tmp (@sorted_phrases) {
if ($tmp->{sort_number} == $chosen_id_now) {
push @sorted_phrases_2, $tmp;
}
}
}
} else {
push @sorted_phrases_2, $_;
}
}
@sorted_phrases = @sorted_phrases_2;
Thanks for any ideas - as I'm stumped :(
Cheers
Andy
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.