This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

alfabet

Old posts that have not been replied to for several years.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

alfabet

Post by caesar »

Is there a way I can line up an row of words in alfabetical order?

Eg.: From "foo, moo, boo" to line up: "boo, foo, moo". Any advices to do so?
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

If the words are in the format you dicribed above, you can do the following

Code: Select all

proc sortit {text} {
  set list [split $text ", "]
  set list [lsort -dictionary $list]
  return [string trimright [join $list ", "] ", "]
}
However, this will only operate if the format is "item, item, item" (coma space, coma space). It would take some pre-sort processing to detect the seperator, and filter and spaces of the end of each element, but it's possible to make a better version.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

If it's "item, item, item" then it's perfect. Thanks.
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

This is probably a slow version, but will dot he trick for other types, and prevent it from breaking.

Code: Select all

proc sortit {text} {
  regsub -all -- {\,\.\@\;\:\\} $text { } text
  foreach a [split $text] {
    if {$a != ""} { lappend list $a }
  }
  return [string trimright [join [lsort -dictionary $list] ", "] ", "]
}
This should work on items seperated by "@", ",", ".", ":" or ";", and will work with or without a space between them.

You can add more delimeters into the regsub, to get better effect.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Dosen;t matter how fast is it, I mean, I don't want it to move like a mad snail climbing a hill or something like this. The list will be just like this: "item, item, item" and I need for a web page..
Once the game is over, the king and the pawn go back in the same box.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I'm stuck in something and I need your advice on this since you've told me how to put a line in alfabetical order.

# set
set db(dir) "files"
set db(no) "1"

# bind
bind dcc n tmp task:tmp

proc task:tmp { hand idx arg } {
global db
catch { glob -type d $db(dir)/* } dirs
foreach dr $dirs {
set line ""
set text [string range $dr [expr [string length files]+$db(no)] end]
set list [split $text ", "]
set list [lsort -dictionary $list]
lappend line [string trimright [join $list ", "] ", "]
putlog "Line: $line, "
}
putlog "Task complete.."
}

And I'm getting the result like this:
Line: tmp,
Line: 2,

When should be: Line: 2, tmp
Actualy, the list that results dosen't have , in it. Anyway, I've tryed without the [string trimright [join $list ", "] ", "] and the same thing happens. What I'm doing wrong? I'm I missing something?
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

From what I can see, you didn't have a list of text "a, b, c, d, e" in the first place.

You are also calling the sort routine on one directory name at a time, rathet than a list of them.

The foreach command, cycles through a list of code, for each alement in a list. As such, the way you are doing it, it outputs each element, before you even have your lists processed.

My sortit function should not be inside the foreach loop.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

After an close inspection and some tests among the reading of things you have said I've managed to complete this task. Here is the result:

# stuff
set db(dir) "files"
set db(no) "1"

# binds
bind dcc n tmp task:tmp

proc task:tmp { hand idx arg } {
global db
catch { glob -type d $db(dir)/* } dirs
foreach dr $dirs {
set dir [string range $dr [expr [string length files]+$db(no)] end]
lappend text $dir
set list [split $text ", "]
set list [lsort -dictionary $list]
}
putlog "Results: [string trimright [join $list ", "] ", "]"
putlog "Task complete.."
}

Thank you for the advices.
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

There is some odd looking - you might want to do the following

Code: Select all

set list [split $text ", "] 
set list [lsort -dictionary $list]
Remove these two lines from there

Just before the first putlog line place

Code: Select all

set list [lsort -dictionary $text]
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Thanks again. Is there a way I can see in how many seconds the creation of the list took?
Once the game is over, the king and the pawn go back in the same box.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

caesar wrote:Thanks again. Is there a way I can see in how many seconds the creation of the list took?
near the start of your procedure...

Code: Select all

set starttime [clock seconds]
before your putlog ...

Code: Select all

set stoptime [clock seconds]
set totaltime [expr $stoptime - $starttime]
and $totaltime will contain the number of seconds it took ...
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Hehe. Thanks. Seems that I've finished my task to create a tcl that will generate a web page with the movies that our private server has to offer. I'll do some minor changes to it and probably make it public, if anyone wants it, just for learn/use from it.

Thanks guys, particulary to ppslim. :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Some final questions if it's possible..

1. For example I have "/mnt/multimedia/hollywood" in the set db(dir) thing. I would like to count how many chars are from "/mnt/" starting with the second "/" ("/" is no. 1..). How to do so?

2. Recomand me a way I can see the date when they have been created and how big they are in MB or whatever.
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

For number 1, I don't realy understand what you are asking for, hwoever, I will have a go.

Use somthing liek this

Code: Select all

set length [string length [lindex [split $item "/"] [expr [llength [split $item "/"]] - 1]]]
As for the second. Read the Tcl manual. The file command will reveale all for filesize, dates, permissions, filetypes. It also provide move, copy and delete functions.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The "/mnt/multimedia/hollywood" is the dir where it searches for the other dirs in the proc. I need a count of "/multimedia/hollywood" to use it here: set dir [string range $dr [expr [string length files]+$db(no)] end] and the $db(no) is the result of that counting thing.

As for the second answer I'll have a look on the TCL manual for the file command.

Thanks again.
Once the game is over, the king and the pawn go back in the same box.
Locked