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

$TextFile = "File.htm";

File.htm is processed and placed in the variable $Text.
Which means, the variable $Text is file.htm, but has been
processed and altered slightly. So now i want to write
$Text back to a file, however, as a different file name, and
in a different directory. The following code only writes
it as the same file name(file.htm), in the same directory.
open (DAT,">$TextFile"); print DAT "$text\n"; close(DAT);
Any Idea's on printing to a different filename and
directory?

Thanx. :)

Lisa

Replies are listed 'Best First'.
Re: Directory Help
by Zaxo (Archbishop) on Jul 13, 2002 at 08:22 UTC

    Just give it a new path:

    my $newpath = '/place/to/put/'; open (DAT,"> ${newpath}${TextFile}") or die $!; print DAT "$text\n" or die $!; close(DAT) or die $!;
    The braces around the variable names in open are to make sure of the variable name boundaries, and all the 'or die's are to make sure the program quits and you get diagnostics if the system operations fail.

    After Compline,
    Zaxo

Re: Directory Help
by Anonymous Monk on Jul 13, 2002 at 08:14 UTC
    my $newfilename="new-$TextFile"; open (DAT,">./../different-dir/$newfilename"); print DAT "$text\n"; close(DAT);
Re: Directory Help
by wolverina (Beadle) on Jul 15, 2002 at 04:55 UTC
    Textfile="file.htm"; use Cwd; chdir("$ENV{DOCUMENT_ROOT}/directory") || die "Can't move to /etc, err +or = $!\n"; my $dir = getcwd; open (DAT,">${dir}${TextFile}") or die $!; print DAT "$text\n" or die $!; close(DAT) or die $!;
    This works fine. Lisa.
      Because you failed to run them correctly. Most probably you do not have mentioned directories

      What have you tried and what was wrong?

      Courage, the Cowardly Dog