Solved

Sorting based on numbers

Posted on 2003-12-03
5
173 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 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