CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
file handles and here documents

 



mckhendry
Deleted

Oct 9, 2000, 8:04 AM

Post #1 of 3 (931 views)
file handles and here documents Can't Post

Hey all,

this is a small example of what I am trying to do:

#!/usr/bin/perl -w

use strict;
use Symbol;

my $fh = gensym;

oneOfManySubroutines($fh);

sub oneOfManySubroutines
{
open $_[0], ">mckhendry.html";

print $_[0] <<HTML;
<html>
--much stuff--
</html>
HTML

close $_[0];
}

If anyone could help me with why I am having trouble printing a here document to a file handle, I would be greatly appreciated.

Thanks,
mckhendry


Cure
User

Oct 8, 2000, 10:09 PM

Post #2 of 3 (931 views)
Re: file handles and here documents [In reply to] Can't Post

Note that if your storing FILEHANDLES in an array or any other expression,
you will have to use a block to return its value instead: <--- that came from perldoc -f print


print { $cure[$] } "cure\n";
print 'CURE' ? STDOUT : STDERR } "me\n";

So, in your case do this -->
print {$_[0]} <<HTML;

Perl loves you Smile


Cure


dws
Deleted

Oct 9, 2000, 11:29 AM

Post #3 of 3 (931 views)
Re: file handles and here documents [In reply to] Can't Post

Unless you have some other use for the gensym'd symbol, you're better off using IO::File.
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

sub OneOfManyRoutines {
$fh = new IO::File "> mckhendry.html";
if (defined $fh) {
print $fh <<HTML;
... stuff ...
HTML
}
}</pre><HR></BLOCKQUOTE>



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives