Example #2 below now opens the file handle into a scalar value of an anonymous hash referenced by $args...use strict; MAIN: { my $fh; open($fh, ">hdt.html") or die("Unable to open output file!"); my $title = 'MY TTILE'; print $fh <<EOF; <html> <head> <title>$title</title> </head> <body> Blah, Blah... </body> </html> EOF close $fh; }
And the following compile time error results!use strict; MAIN: { my $args = {}; open($args->{fh}, ">hdt.html") or die("Unable to open output file! +"); my $title = 'MY TTILE'; print $args->{fh} <<EOF; <html> <head> <title>$title</title> </head> <body> Blah, Blah... </body> </html> EOF close $fh; }
D:\Development\Perl\HereDocTest>hdt2.pl<br> Scalar found where operator expected at D:\Development\Perl\HereDocTes +t\hdt2.pl line 10, near "<title>$title"<br> (Missing operator before $title?)<br> Bareword found where operator expected at D:\Development\Perl\HereDocT +est\hdt2.pl line 11, near "</head"<br> (Might be a runaway multi-line // string starting on line 10)<br> (Missing operator before head?)<br> Bareword found where operator expected at D:\Development\Perl\HereDocT +est\hdt2.pl line 13, near "Blah"<br> (Missing semicolon on previous line?)<br> syntax error at D:\Development\Perl\HereDocTest\hdt2.pl line 9, near " +head>"<br> Search pattern not terminated at D:\Development\Perl\HereDocTest\hdt2. +pl line 15<br>
This is not a major issue, but I've tried:use strict; MAIN: { my $args = {}; open($args->{fh}, ">hdt.html") or die("Unable to open output file! +"); my $title = 'MY TTILE'; my $fh = $args->{fh}; print $fh <<EOF; <html> <head> <title>$title</title> </head> <body> Blah, Blah... </body> </html> EOF close $fh; }
And nothing results in differing errors. The behavior here is consistent using either UNIX & Win32 Perls. TIA, MJDprint ($args->{fh}) <<EOF; print +$args->{fh} <<EOF; print +($args->{fh}) <<EOF;
In reply to FileHandles as members of anon hash & Here docs??? by apostate1100
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |