Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Creating a file by using perl

by freekngeek (Acolyte)
on Mar 28, 2013 at 10:46 UTC ( #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 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 So I was doing this. I was trying to create a new file( and printing out all the lines and commands into this file. For an example I need these lines in my new 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 = ""; 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 line 12, near "" +libName = "cmos28shp" (Missing operator before cmos28shp?) String found where operator expected at line 12, near "cmo +s28shp"\n"" syntax error at line 12, near ""libName = "cmos28shp" BEGIN not safe after errors--compilation aborted at 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 = ""; 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 + line 12.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025935]
Approved by marto
[virtualsue]: I have made a post for the first time in ... years
[marto]: hey virtualsue!
Eily thought about Neko Case first, something might be wrong with my brain's wiring
[virtualsue]: I recommended dbic-migration even though I am having trouble with it this week. It might be my fault.
[ambrus]: wow! I haven't seen you here for a long time, virtualsue
virtualsue waves back
[Eily]: it would have been 2 years in 2 weeks actually. And welcome back virtualsue :)
[Corion]: I think I saw virtualsue more recently in person than online :-D
[virtualsue]: It's true that there was a bigger gap between the 2 yr old post and the one before it
[ambrus]: yes, I probably just didn't see you two years ago, because I'm not in perlmonks much

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2017-09-26 13:50 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (295 votes). Check out past polls.