Inserting perl code into a file

Discussion in 'Perl Misc' started by Gary Mayor, Jan 1, 2004.

  1. Gary Mayor

    Gary Mayor Guest

    Hi,
    I'm trying to insert some perl code into another file. If I use

    $code = qq{
    $a = "1";
    if ($a eq "1") {print "A = 1";}
    };
    open(FILE,">runme.cgi");
    print FILE $code;
    close FILE;

    It just says syntax error at the end of the file. I've tried escaping
    the $ with \$ but that didn't work. Does anyone know how to do this?

    Thanks

    Gary Mayor
     
    Gary Mayor, Jan 1, 2004
    #1
    1. Advertising

  2. Gary Mayor <> wrote:

    > I'm trying to insert some perl code into another file. If I use
    >
    > $code = qq{



    > It just says syntax error at the end of the file.



    It said more than that when you enabled warnings.

    You should always enable warnings when developing Perl code!


    > Does anyone know how to do this?



    Yes.

    Delete one "q" character.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 2, 2004
    #2
    1. Advertising

  3. Gary Mayor wrote:
    > I'm trying to insert some perl code into another file. If I use
    >
    > $code = qq{
    > $a = "1";
    > if ($a eq "1") {print "A = 1";}
    > };
    > open(FILE,">runme.cgi");
    > print FILE $code;
    > close FILE;
    >
    > It just says syntax error at the end of the file. I've tried
    > escaping the $ with \$ but that didn't work.


    Then try harder, because it should.

    Alternatively you can replace the qq// operator with the q// ditto.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jan 2, 2004
    #3
  4. Gary Mayor

    Gary Mayor Guest

    Sorry everyone it was a late night that wasn't the problem it was a
    missing }. Darn...... Thanks anyway


    Gary Mayor wrote:
    > Hi,
    > I'm trying to insert some perl code into another file. If I use
    >
    > $code = qq{
    > $a = "1";
    > if ($a eq "1") {print "A = 1";}
    > };
    > open(FILE,">runme.cgi");
    > print FILE $code;
    > close FILE;
    >
    > It just says syntax error at the end of the file. I've tried escaping
    > the $ with \$ but that didn't work. Does anyone know how to do this?
    >
    > Thanks
    >
    > Gary Mayor
    >
     
    Gary Mayor, Jan 2, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wjer
    Replies:
    0
    Views:
    2,067
  2. Ian Collins
    Replies:
    3
    Views:
    1,015
    Thomas Beckmann
    Jan 19, 2009
  3. Benjamin Joldersma

    Programmatically inserting controls into old legacy Response.Write style code

    Benjamin Joldersma, May 13, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    211
    Benjamin Joldersma
    May 13, 2004
  4. Replies:
    2
    Views:
    165
    Julia De Silva
    Dec 7, 2004
  5. Slain
    Replies:
    1
    Views:
    106
    J. Gleixner
    May 18, 2007
Loading...

Share This Page