in reply to File opening problems

open (OUTFILE, ">@htmlLines")

Are you sure about that second argument? Does the file name you want to write to indeed come from joining the elements of that array with spaces? Are you sure you don't want to use a regular file name?

or die("Can't rewrite the HTML file.\n");

For anything other than run-once programs, I include the filename I used in the open statement in the error message.

Abigail

Replies are listed 'Best First'.
Re: Re: File opening problems
by Tricky (Sexton) on Aug 19, 2003 at 13:05 UTC
    You mean replace:
    open (OUTFILE, ">@htmlLines") or die("Can't rewrite the HTML file.\n") +;
    with this? The actual file name?
    open (OUTFILE, ">E:/Documents and Settings/Richard Lamb/My Documents/H +TML/test1InDocCSS.html") or die ("Can't open E:/Documents and Setting +s/Richard Lamb/My Documents/HTML/test1InDocCSS.html\n");
    So I should be passing the file path as an argument, not the array variable I'm using to store the HTML? Many thanks, Richard
      open needs a filename, not the content of the file to be. If you wouldn't give the file, how is Perl supposed to know which file to open?
      my $file = "whatever"; open my $out, ">", $file or die "Failed to open $file: $!"; print $out @htmlLines; close $out or die "Failed to close $file: $!";

      Abigail

        Just replaced the duff code with this:
        # Replacing original file with reformatted file! my @htmlFile = "@htmlLines"; open (OUTFILE, ">E:/Documents and Settings/Richard Lamb/My Documents/H +TML/test1InDocCSS.html") or die("Can't rewrite the HTML file.\n"); print (OUTFILE @htmlFile); close (INFILE); close (OUTFILE);
        It works! Fantastic!I opened the original html file on my hard-drive a +nd, hey-presto, no images or hyperlinks... Thanks a million Abigail, Richard