Re: Using Block instead of Module?
- To: mathgroup at smc.vnet.net
- Subject: [mg24265] Re: Using Block instead of Module?
- From: "Rasmus Debitsch" <debitsch at Zeiss.de>
- Date: Wed, 5 Jul 2000 23:10:46 -0400 (EDT)
- Organization: Customer of UUNET Deutschland GmbH
- References: <8jtf5f$ik5@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hello, outputTest[ lst_List, id_Integer] := Module[{ fname, tmp = lst }, fname = ToString[id] <> ".txt"; Put[tmp, fname]; ]; does the job. Regards -- Rasmus Debitsch Carl Zeiss Lithos GmbH Carl Zeiss Strasse D-73447 Oberkochen eMail : debitsch at zeiss.de Wen-Feng Hsiao <d8442803 at student.nsysu.edu.tw> schrieb in im Newsbeitrag: 8jtf5f$ik5 at smc.vnet.net... > Dear listers, > > I try to output results to a file whose name is variable, and find Module > statement cannot fulfill this purpose, only Block can do. For example, > > outputTest[lst_List, id_Integer] := Module[{fname, tmp = lst}, > fname = ToString[id] <> ".txt"; > ToExpression["tmp >>" <> fname]; > ]; > > outputTest[{1, 2, 3}, 3] > > The output file is 3.txt, but the content is "tmp". But if I change > Module statement into Block as below: > > outputTest[lst_List, id_Integer] := Block[{fname, tmp = lst}, > fname = ToString[id] <> ".txt"; > ToExpression["tmp >>" <> fname]; > ]; > > outputTest[{1, 2, 3}, 3] > > The output file is 3.txt, and the content is correct, {1, 2, 3}. How if > one used to use Module, like me, should do for the same purpose? > > Wen-Feng > >