Solved

Sorting based on numbers

Posted on 2003-12-03
5
174 Views
Last Modified: 2013-12-25
Hi there,

Iam trying to make a sorting based on a counter but it seems that i get messup because when i try to sort some based on for example "3" all number that have a "3" will sorted as well and i dont want it. How can I sort ONLY the "3" and not the 13, 33, 23, 53, etc?
heres the code iam using

if ($yixa2 =~ 3) {
$tdtag3 = "</tr><tr>"; }
else {
$tdtag3 = "";
}

Any ideas?
Polos
0
Comment
Question by:polos
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 9872368
if ($yixa2 == 3) {
0
 
LVL 84

Accepted Solution

by:
ozo earned 25 total points
ID: 9878962
$tdtag3 = $yixa2==3&&"</tr><tr>";
0
 
LVL 3

Assisted Solution

by:rkosai
rkosai earned 25 total points
ID: 9893186
It seems that you would best be served by placing this into a hash, then sorting the hash values by number.

For purposes of example, I am going to create a hash; you would use your own data here.
my %values;
$values{23} = 'caption0';
$values{13} = 'caption1';
$values{33} = 'caption2';
$values{3} = 'caption3';


You could then use this code to print the :

foreach(sort {$a <=> $b} keys %values) {
  print "<tr><td>$values{$_}</td><td>$_</td></tr>\n";
}

This would yield:

<tr><td>caption3</td><td>3</td></tr>
<tr><td>caption1</td><td>13</td></tr>
<tr><td>caption0</td><td>23</td></tr>
<tr><td>caption2</td><td>33</td></tr>

Which is what I think you're trying to accomplish.

Otherwise, if you're only trying to find the value "3" by itself, you can use the expression,

if ($x == 3) {
  #do action
}

Good luck.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question