Re: serach and replace number
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: serach and replace number

From: miguel sofer <miguel.sofer@gmail.com>
Date: Thu Jul 28 2005 - 13:39:42 CEST

The problem is still underspecified. Let me assume:
 1. the output order is not relevant
 2. all items are numeric; +0 and -0 cannot appear in the data
 3. the input order is relevant; the last appearance is the important
one

Then one solution is

% proc filter data {
    foreach item $data {
        set uns [expr {abs($item)}]
        if {$item > 0} {
            set res($uns) {}
        } else {
            unset -nocomplain res($uns)
        }
    }
    array names res
}
% set d {+1 +4 +6 +3 +5 +2 -1 -3}
+1 +4 +6 +3 +5 +2 -1 -3
% filter $d
4 5 2 6

If those assumptions do not match your problem, please specify it in
more detail.

Cheers
Received on Thu Sep 29 14:27:44 2005