Hi,
When using sort on an associative array:
foreach $key (sort(keys(%opalfabet))){
$value = $opalfabet{$key};
$result .= $value;
}
How does it handle double values?
It seems to me that it removes them, is that true? If so, is there a way to get... (2 Replies)
hi all
i was going through some perl code i came across this line and i am not getting what is exactly going on ..
$$this{localtion} = GetName->GetVarName("EXE_DIR") ;
what is the red part doing in above code (2 Replies)
Hi Everyone,
I have:
my @No=qw(032106 032630 0380 034010 035110 0354801111);
my $str_No=join(';', @No);
I have a string $strA="03263033", so in order to determine this $strA area code matches with @No, I can do:
if ( (rindex($str_No,substr($strA,0,5))))== -1) ) {
print "Not... (1 Reply)
How is it possible to sort different nummeric values within an Array. But i don`t want the highest or the lowest. I need the most frequently occurring value.
For examble:
My Array has to following values = (200 404 404 500 404 404 404 200 404)
The result should be 404
The values are... (3 Replies)
Hi All,
I have an array in perl as @match = (201001,201002,201001,201002);
I am trying to sort this array as
@match = sort(@match);
print "@match";
I dont see the output sorted any answers
I also tried another way, but still the results are not sorted
foreach my $match (sort { $a... (2 Replies)
Hi,
i have a txtfile with the format <Nr>tab<word>tab<other stuff>new line and i want to sort the <word>-colum with a perl script.
My textfile:
<Nr>tab<word>tab<other stuff>new line
6807 die ART.Acc.Sg.Fem
6426 der ART.Gen.Sg.Fem
2 die ART.Nom.Sg.Fem
87 auf APPR.--
486 nicht PTKNEG.--... (1 Reply)
Hi all,
Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM.
Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers.
At the moment am... (3 Replies)
I am using this line of perl code to change the file format and remove ^M at the end of each line in files:
perl -i -pe's/\r$//;' <name of file here>
Can you explain to me what this code does, and translate it into bash/awk/sed? (2 Replies)
@sorted = sort { $a <=> $b } @unsorted;
I am having hard time understanding how this works? I know the output but interested to know the working.
Thanks in advance. (2 Replies)
Discussion started by: Tanu
2 Replies
LEARN ABOUT PHP
uasort
UASORT(3) 1 UASORT(3)uasort - Sort an array with a user-defined comparison function and maintain index associationSYNOPSIS
bool uasort (array &$array, callable $value_compare_func)
DESCRIPTION
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with, using a
user-defined comparison function.
This is used mainly when sorting associative arrays where the actual element order is significant.
Note
If two members compare as equal, their relative order in the sorted array is undefined.
PARAMETERS
o $array
- The input array.
o $value_compare_func
- See usort(3) and uksort(3) for examples of user-defined comparison functions.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
Example #1
Basic uasort(3) example
<?php
// Comparison function
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
// Array to be sorted
$array = array('a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4);
print_r($array);
// Sort and print the resulting array
uasort($array, 'cmp');
print_r($array);
?>
The above example will output:
Array
(
[a] => 4
[b] => 8
[c] => -1
[d] => -9
[e] => 2
[f] => 5
[g] => 3
[h] => -4
)
Array
(
[d] => -9
[h] => -4
[c] => -1
[e] => 2
[g] => 3
[a] => 4
[f] => 5
[b] => 8
)
SEE ALSO usort(3), The comparison of array sorting functions.
PHP Documentation Group UASORT(3)