Version 9 of For-mat

Updated 2012-12-29 19:40:53 by HJG

HJG 2012-12-29 - Demo for re-formatting string to list.

 # http://wiki.tcl.tk/37505
 # for-mat2.tcl - HaJo Gurt - 2012-12-29

 #: Re-Format long string to a list of filenames/URLs
 # e.g. to be used with  "wget -i file"

  set Hdr "For-Mat2"

 ####+####1####+####2####+####3####+####4####+####5####+####6####+####7####+###
 ## Console-settings, to allow running in wish as well as in tclsh:
   catch { console show }
   catch { wm withdraw . }
 # catch { console eval { .console config -bg grey -fg blue } }
 # Resize & put at top-right corner on 1024x768:
 ##catch { console eval { wm geometry . 56x12+550+0 } }
   catch { console title "$Hdr" }

   proc q {} { exit }
 ####+####1####+####2####+####3####+####4####+####5####+####6####+####7####+###
   puts "# $Hdr:"

 # set PL  {bild01.jpg bild02.jpg bild03.jpg} 
 ##
 # set P1 "http://blah.de/fasel/"
 # set P2 "bild01.jpg"
 ##
 # set url "http://blah.de/fasel/bild01.jpg"

   set P1 "http://blah.de/fasel/"
   set PS {bild01.jpg,bild02.jpg,bild03.jpg} 
   puts "# PS=$PS."

   set PL  [string map -nocase { "," " "} $PS]
   puts "# PL=$PL."

   set i 0
   foreach P2 $PL {
     incr i
     set url "$P1$P2"
     set filename "XY_$P2"

   # puts "$i.   URL=$url."
   # puts "filename=$filename."
     puts $url
   }
   puts "# Done."
 #.

Output:

# For-Mat2:
# PS=bild01.jpg,bild02.jpg,bild03.jpg.
# PL=bild01.jpg bild02.jpg bild03.jpg.
http://blah.de/fasel/bild01.jpg
http://blah.de/fasel/bild02.jpg
http://blah.de/fasel/bild03.jpg
# Done.

See also: for, foreach, I love foreach, string, regexp, regsub