On Thu, 2013-02-21 at 01:50 +0100, Charles Goyard wrote:
> IOhannes m zmoelnig wrote:
> > you can tell [textfile] to use CR/LF/CRLF as line delimiters by
> > opening the file in "cr" mode, like
> >  [open file.txt cr(
> > 
> > then you will need to stop through the lines by [bang(ing [textfile]
> > till the end is reached. if you want to read the entire file at once,
> > use [until] (with the 2nd outlet of [textfile] fed back to the 2nd
> > inlet of [until], so it stops banging once the textfile is done.
> > convert each line with [any2bytes], use [list append] to append '10'
> > (the newline), and append those lists using another [list append].
> 
> Ok here's my take to this. I was unable to make it work with only two
> list append, so I used 1 append and 2 prepend. There sure is a more
> logical way to that. But at least it works :).
> 
> Please correct my patch and help me learn !
> 
> Thanks a lot for your help.

Your patch breaks when you have a line with a comma in your text file.
Such a line is broken into two lines. 

Regarding your insistence to do that task with Pd, I think you should
reconsider your reasoning. Pd is not particular strong in string
processing, exactly because of reasons like this. IMHO, your best bet is
to not use character representation at all in Pd which is probably the
only safe way not to get in conflict with special characters in Pd (at
least as long as there isn't a proper way to escape them).

See attached example with  [mrpeach/binfile] -> [text3d].

This example doesn't do any processing at all, it only passes the data
"untouched" to [text3d]. If you really want to do some processing, I'd
probably do that outside of Pd. There are plenty of ways to roll your
own external class with any of several scripting languages (bash, lua,
python, tcl, etc.). I'd probably offload all the real string processing
to such an external. 

Roman

#N canvas 0 57 467 569 10;
#X declare -lib moocow -lib Gem -lib mrpeach;
#X obj 103 486 gemhead;
#X obj 22 78 gemwin;
#X obj 174 526 text3d;
#X obj 22 28 declare -lib moocow -lib Gem -lib mrpeach;
#X msg 22 53 create \, 1 \, frame 5;
#X obj 329 434 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 329 455 openpanel;
#X msg 329 480 font \$1;
#X obj 193 287 mrpeach/binfile;
#X msg 213 228 clear \, read essai2.txt cr \, rewind;
#X msg 193 314 add2 \$1;
#X obj 173 180 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 193 251 until;
#X msg 308 296 set;
#X obj 174 204 t b b b;
#X obj 174 438 list prepend string;
#X obj 174 464 list trim;
#X msg 174 376;
#X connect 0 0 2 0;
#X connect 4 0 1 0;
#X connect 5 0 6 0;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X connect 8 0 10 0;
#X connect 8 2 12 1;
#X connect 9 0 8 0;
#X connect 10 0 17 0;
#X connect 11 0 14 0;
#X connect 12 0 8 0;
#X connect 13 0 17 0;
#X connect 14 0 17 0;
#X connect 14 1 12 0;
#X connect 14 2 13 0;
#X connect 14 2 9 0;
#X connect 15 0 16 0;
#X connect 16 0 2 0;
#X connect 17 0 15 0;
_______________________________________________
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to