Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Hash refs and printing to FD
- January Weiner
April 16, 2009, 10:35 am
rate this thread
I want to print to a file descriptor that sits in a hash ref:
my %hash ;
my $hash_ref = \%hash ;
open( $hash, ">test" ) or die "Can't write to file test: $!\n" ;
print $hash_ref-> "Test\n" ;
This throws the following error:
syntax error at test.pl line 12, near "} "Test\n""
Why is that so? And what should I do, except for the obvious code below?
my $fd = $hash_ref-> ;
print $fd "Test\n" ;
Re: Hash refs and printing to FD
perldoc -f print
Note that if you're storing FILEHANDLEs in an array, or if
you're using any other expression more complex than a scalar
variable to retrieve it, you will have to use a block returning
the filehandle value instead:
Follow the solution given in the documentation.
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
- » FAQ 4.69 How can I make the Perl equivalent of a C structure/C++ class/hash or array of ha...
- — Previous thread in » PERL Discussions