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

I am using the script below and having a problem. I am trying to open up 2 different files so the user can later use the layout of their website with the script. It doesn't work and AdminPro says you cannot open the file in such a manner when using Strict. I am rather new to perl so I'd prefer you don't throw in some really advanced stuff I couldn't understand. If it isn't too much to ask I'd also like someone to fill me in on why you cannot open a file under these conditions.

Thanks!

#!/usr/local/bin/perl -w use strict; my %form = ( author => undef, distributor => undef, copyright => undef, keywords => undef, description => undef, distribution => undef, robots => undef, language => undef, generator => undef, ); use CGI; my $query = CGI->new; print $query->header; %form = %{$query->Vars}; open(HEADER, "header.html") or die("Cannot open file: $!\n"); print <<EOF < meta name="author" content="$form{'author'}"> < meta name="distributor" content="$form{'distributor'}"> < meta name="copyright" content="$form{'copyright'}"> < meta name="keywords" content="$form{'keywords'}"> < meta name="description" content="$form{'description'}"> < meta name="generator" content="SpyderTag V1.0!"> < meta name="robots" content="$form{'robots'};"> < meta name="language" content=$form{'language'}"> < meta name="distribution" content="$form{'distribution'} EOF open(FOOTER, "footer.html") or die("Cannot open file: $!\n"); # open(FH, "> sample.txt") or die("Cannot write to file: $!\n");

Replies are listed 'Best First'.
Re: How do you open a file when using strict?
by dws (Chancellor) on Aug 05, 2002 at 00:54 UTC
    It doesn't work ...

    It doesn't work how? If you're reporting a problem, it really helps to say something more than "it doesn't work."

    I'm guessing that your problem is that   print <<EOF should be   print <<EOF;

Re: How do you open a file when using strict?
by Nightblade (Beadle) on Aug 05, 2002 at 00:54 UTC
    Here is error in this code.
    Need semicolon after print <<EOF

    print <<EOF; < meta name="author" content="$form{'author'}"> < meta name="distributor" content="$form{'distributor'}"> < meta name="copyright" content="$form{'copyright'}"> < meta name="keywords" content="$form{'keywords'}"> < meta name="description" content="$form{'description'}"> < meta name="generator" content="SpyderTag V1.0!"> < meta name="robots" content="$form{'robots'};"> < meta name="language" content=$form{'language'}"> < meta name="distribution" content="$form{'distribution'} EOF
Re: How do you open a file when using strict?
by DamnDirtyApe (Curate) on Aug 05, 2002 at 00:59 UTC

    You absolutely can open a file for writing when use strict is on effect. Try the following code to prove it:

    #! /usr/bin/perl use strict ; use warnings ; $|++ ; open OUT, '>out.txt' or die "Couldn't open the file: $!" ; print OUT "Hello, World!\n" ; close OUT ; exit ; __END__

    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: How do you open a file when using strict?
by smalhotra (Scribe) on Aug 05, 2002 at 01:48 UTC
    Not to force my own style on others but ... I would suggest using the FileHandle module:
    use FileHandle; my $fh_header = new FileHandle; $fh_header->open("header.html") or die("Cannot open file: $!\n"); print $fh "stuff ..."; my $fh_footer = new FileHandle; $fh_footer->open("footer.html") or die("Cannot open file: $!\n");
    I have also started using the q() and qq() quotation methods instead of here docs. I feel they're slightly easier to handle.
    print qq( < meta name="author" content="$form{'author'}"> < meta name="distributor" content="$form{'distributor'}"> < meta name="copyright" content="$form{'copyright'}"> < meta name="keywords" content="$form{'keywords'}"> < meta name="description" content="$form{'description'}"> < meta name="generator" content="SpyderTag V1.0!"> < meta name="robots" content="$form{'robots'};"> < meta name="language" content=$form{'language'}"> < meta name="distribution" content="$form{'distribution'} );
    Hope this helps.
    ----------------------------
    $will->code for @food or $$;
Re: How do you open a file when using strict?
by theorbtwo (Prior) on Aug 05, 2002 at 01:19 UTC

    Watch the attributions on your quotes, and don't belive everything you hear on the CB. I said that, and I was wrong, wrong, wrong.


    Confession: It does an Immortal Body good.