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

ok below works ... next question is will this work as part of a subroutine? (The reason for all this foo is that I have to wite to multiple different files all at once) trying to figure this out. I want to pass all lines inside FRED to HANDLE ... Seems simple enough, right?
============ Partial Code ================== #!c:\perl\bin\perl # Predeclare vars $var1="c\:"; $var2="/code/"; $thefile="$var1"."$var2"."blah.conf"; print($thefile,"\n"); open HANDLE,'>',"$thefile" or die; print(HANDLE <<FRED); <Directory "$var1$var2"> </Directory> FRED

Replies are listed 'Best First'.
Re: Can't pass filehandle value
by dpuu (Chaplain) on Nov 06, 2003 at 02:46 UTC
    you've forgotten to open the file --
    open HANDLE, ">$HANDLE" or die;
    You might want to rename $HANDLE to $filename, too.

    --Dave.

Re: Can't pass filehandle value
by BrowserUk (Patriarch) on Nov 06, 2003 at 02:55 UTC

    You still haven't opened the file.

    P:\test>perl open HANDLE, '>', 'junk' or die $!; my $var1 = 'test'; my $var2 = 'test2'; print HANDLE <<FRED; me you us them $var1 $var2 FRED ^Z P:\test>type junk me you us them test test2

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!
    Wanted!

Re: Can't pass filehandle value
by Roger (Parson) on Nov 06, 2003 at 02:53 UTC
    Perhaps you should learn how to open/close/write-to a file, and do a few beginner's tutorial on Perl monks.

    use strict; use IO::File; my $var1='test'; my $var2='test2'; my $f = new IO::File "$var1/$var2/blah.conf","w" or die "Can't create +blah"; print $f <<FRED blah blah ... FRED ;
    Update: mis-interpreted the <<FRED bit. Ouch.

    You code has -
    open HANDLE, ">$HANDLE" or die; $HANDLE="$var1/$var2/blah.conf";
    You are trying to open a file before you assign the file name? That's probably why your script didn't work in the first place.


    I see you have fixed that problem in your original post.

      I can't use IO::File.
        Well, in that case you could do this -
        use strict; my $var1='test'; my $var2='test2'; open HANDLE ">$var1/$var2/blah.conf" or die "Can't create blah"; print HANDLE <<FRED blah blah ... FRED ; close HANDLE;