Can not print blocks to files with <<

Discussion in 'Perl Misc' started by WH, Sep 18, 2004.

  1. WH

    WH Guest

    print << 'okok';
    lalala

    okok

    works fine, but with I try to do the same thing to write to a file


    print $OUTPUTFILE << 'okok';
    lalala

    okok

    not working
     
    WH, Sep 18, 2004
    #1
    1. Advertisements

  2. WH

    Tintin Guest

    "Not working" is a poor description of the problem. It would have been
    better if you gave the actual error message generated, ie:

    Can't use an undefined value as a symbol reference at foo line 1.

    Anyway, move the $ from the filehandle and assuming you opened the file
    correctly, you'll be fine.
     
    Tintin, Sep 18, 2004
    #2
    1. Advertisements

  3. WH

    WH Guest

    $ has nothing to do with it, as my handle has $. but I fixed it. here is the
    current code

    print {$OUTPUT} << "header";

    I have to {} the output handle. don't know why.
     
    WH, Sep 18, 2004
    #3
  4. To not confuse the print() function you can do

    print $OUTPUTFILE (<< 'okok');

    or

    print $OUTPUTFILE <<'okok'; # space after '<<' removed
     
    Gunnar Hjalmarsson, Sep 18, 2004
    #4
  5. WH

    Eric Amick Guest

    More than likely because

    $xyz << "abc"

    looks like you're using the left shift operator. Putting curly brackets
    around the filehandle makes your intent clear.
     
    Eric Amick, Sep 19, 2004
    #5
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.