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.

weird

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

weird

Post by caesar »

Using the folowing code:

Code: Select all

catch { glob -type f $::db(path)/$film/* } files
foreach bla $files { 
set subtitle "No"
if {[string match "*.sub*" $bla]} { set subtitle "Yes" }
}
where the $bla variable looks like:
"/home/irc/raid/upload/movies/2 Fast 2 Furious/2 Fast 2 Furious.sub" sometimes is working, sometimes it dosen't.. When I do a manual test like .tcl set bla "/home/irc/raid/upload/movies/2 Fast 2 Furious/2 Fast 2 Furious.sub" ; if {[string match "*.sub*" $bla]} { putlog "yes" } it's working all the time but when I put it to do the test with if {[string match "*.sub*" $bla]} { set subtitle "Yes" } sometimes it fails.. Any sugestions how to *fix* this?
Once the game is over, the king and the pawn go back in the same box.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: weird

Post by user »

Try something like this:

Code: Select all

if {[llength [glob -nocomplain -types f -dir [file join $::db(path) $film] *.sub]]} {has subs} {dont}
btw: I think the reason you got different results might have to do with glob matching chars in the mask you used (eg. "[" in dir names)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

It dose seem to be working fine now. Thank you.
Once the game is over, the king and the pawn go back in the same box.
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

also had some wired error the last days..

Code: Select all

set in [open $file r]
while {![eof $in]} { 
  set line [gets $in]
  set line [lindex $line 0 end] #this is cos every line starts with 2 space chars
.....
a line in the file started this way:
"Text": sometext
it worked with each line, but not with that one (error : list element in quotes followed by ":" instead of space)
i fixed it with a "string range" from 3 to end

or:

Code: Select all

proc loadall { string } {
  set files [exec ls scripts/]
  foreach z [split $files \n] { 
    if {[string match "$string" $z]} {		
      utimer 2 "source scripts/$z"              # <- 1rst way, works
      source scripts/$z                         # <- 2nd way, doesnt work
		}
	}
}
both return the "file.tcl been loaded" thats on the bottom of each file, but with the 2nd way the vars that have been set at the top of the files arent set, the 1rst way sets them....
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

GodOfSuicide wrote:also had some wired error the last days...
That's not weird at all... You use list commands on strings and get what you deserve :wink:
Use 'string trim' to get rid of the spaces.

Use 'glob' to list files (there's probably errors in the files sourced by the timers too, but they happen in separate calls, so it wont prevent the rest from loading)

If you don't get what I mean, I'll come back later and clean up my post..I'm in a bit of a hurry right now...bbl
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

the first i get :P

the 2nd works fine with ls too and the sources with utimers work fine (everything gets loaded)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

GodOfSuicide wrote:the 2nd works fine with ls too and the sources with utimers work fine (everything gets loaded)
I still think using the built in command to list files would be better.

The reason the variables "disappear" is because you source the files from within the proc and because of that, their code is executed in the scope of the proc (so the variables are deleted when the proc returns)

Use 'uplevel #0 [list source $z]' to get it executed in the global namespace (like the timers do)

Code: Select all

proc loadall {pattern} {
  foreach f [glob -nocomplain -types f -dir scripts $pattern] {
    uplevel #0 [list source $f]
  }
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

caesar, your code proably is working correctly, however, you are forgetting your code is in a loop.

For every loop of your code, you are setting a value to "No". Thus, once you set the value to "Yes" and there are more files, the it returns to "No"
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

ppslim wrote:caesar, your code proably is working correctly, however, you are forgetting your code is in a loop.

For every loop of your code, you are setting a value to "No". Thus, once you set the value to "Yes" and there are more files, the it returns to "No"
Damn, you're right. I thought I saw a 'break' in there (would make sense :P), but using -dir to specify the dir will prevent matching problems and -nocomplain is "cleaner" that catching the glob :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Umm.. yes, that makes sence now. Forgot that I was in a loop thing and yes, in some cases there are more than 1 file so happens exactly like you've said. Thanks for pointing that out 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 »

Well, I'm still "confused" how I should "skip" the other files and see if only a .sub file is there.. I've tryed different alternatives but with no notable success. Any sugestions? :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

caesar wrote:Well, I'm still "confused" how I should "skip" the other files and see if only a .sub file is there.. I've tryed different alternatives but with no notable success. Any sugestions? :)
You should 'break' out of the loop when a match is found, or set the negative value outside the loop and only change the value when/if a match is found.

What's wrong with the code I suggested? It won't even need a loop.

Here's a even less readable one-liner for you ;P

Code: Select all

set subtitles [expr {[llength [glob -nocomplain -types f -dir [file join $::db(path) $film] *.sub]]?"Yes":"No"}]
Locked