Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Creating a file by using perl

by freekngeek (Acolyte)
on Mar 28, 2013 at 10:46 UTC ( [id://1025935]=perlquestion: print w/replies, xml ) Need Help??

freekngeek has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone, I am new to perl and here is my problem. I have two files. First one is perl script which is reading a text file and parsing some important values and putting into an array for future use. Second file is skill.il which is a Cadence framework file that do some random stuff, I need values from perl script and want to use those values in my skill.il. So I was doing this. I was trying to create a new file(skill.il) and printing out all the lines and commands into this file. For an example I need these lines in my new skill.il file:

libName = "cmos28shp" ; device library name tech_lib = "cmos28shp" techFileID = techOpenTechFile( "cmos28shp" "tech.db" "r") lib = ddGetObj(libName) ;; Verify the library exista +nce if(lib == nil then fprintf(stderr "ERROR: Invalid library. %L .\n" libName) return(nil) else
So I was doing this in perl:
my $outfile = "skillfile.il"; open FH, ">> $outfile"; print FH "libName = "cmos28shp"\n"; print FH 'tech_lib = "cmos28shp"'; close FH;
I am not sure if it's a right way to generate this file, I am also getting errors like these :
Bareword found where operator expected at testfile.pl line 12, near "" +libName = "cmos28shp" (Missing operator before cmos28shp?) String found where operator expected at testfile.pl line 12, near "cmo +s28shp"\n"" syntax error at testfile.pl line 12, near ""libName = "cmos28shp" BEGIN not safe after errors--compilation aborted at testfile.pl line 1 +9.
So I hope if you can show me some direction and suggest me how can I fix this. Thanks

Replies are listed 'Best First'.
Re: Creating a file by using perl
by hdb (Monsignor) on Mar 28, 2013 at 10:57 UTC

    You need to put \ in front of quotes if you want them printed.

    print FH "libName = \"cmos28shp\"\n";
      My preferred method is to use heredoc style so there is only one print statement and your quotes can remain "natural"....
      my $outfile = "skillfile.il"; open FH, ">> $outfile"; print FH <<EOF; libName = "cmos28shp" tech_lib = "cmos28shp" EOF close FH;

      N.B. Note that using ">>" to open skillfile appends data to it, so running the program twice will duplicate the data in the file.

      A Monk aims to give answers to those who have none, and to learn from those who know more.

        Thanks a lot man, It's working fine. Just one more thing. Now, when I am printing out those lines, I need to use values from my array. I have a subroutine in which I am parsing values from a text file and the values are stored in an array, so can I just call a subroutine and use array reference to print out my text with the values from that array ? Because when I am doing that It's giving me this error

        Global symbol "$one_ref" requires explicit package name at testfile.pl + line 12.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1025935]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found