Tuesday 15 June 2010

Perl use variable as a file name -


How to create a file containing the variable containing the underscore between them, let me get this $ variable1_ $ vraiable2_ $ variable3.txt

  @ values ​​= split (/. /. $ Line) My $ fpga_name = $ values ​​[0] need to be created with a file like I; My $ block_name = $ value [1]; My $ mem_name = $ value [2]; My $ memfilename = "mem_init / $ fpga_name_ $ block_name_ $ mem_name.txt"; Open (WRITE_MEM_FILE, "> gt; & gt; Memphilam"); Print WRITE_MEM_FILE "$ line \ n";  

You can simply wrap all the variables in curly braces:

My memfilename = "mem_init / $ {fpga_name} _ $ {block_name} _ $ {mem_name} .txt";

Keep in mind that you need memfilename before $ in your open statement, otherwise you will get just one letter:

  open (WRITE_MEM_FILE, "> gt; & gt; $ memfilename");  

No comments:

Post a Comment