Solved

Sorting based on numbers

Posted on 2003-12-03
5
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

710 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