Hash refs and printing to FD

J

January Weiner

Hi,

I want to print to a file descriptor that sits in a hash ref:

my %hash ;
my $hash_ref = \%hash ;
open( $hash{fd}, ">test" ) or die "Can't write to file test: $!\n" ;

print $hash_ref->{fd} "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->{fd} ;
print $fd "Test\n" ;

j.
 
A

A. Sinan Unur

Hi,

I want to print to a file descriptor that sits in a hash ref:

my %hash ;
my $hash_ref = \%hash ;
open( $hash{fd}, ">test" ) or die "Can't write to file test: $!\n" ;

print $hash_ref->{fd} "Test\n" ;

This throws the following error:
syntax error at test.pl line 12, near "} "Test\n""

Why is that so?

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:
And what should I do

Follow the solution given in the documentation.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
T

Tim McDaniel

Thanks, Sinan!

I was looking for something in the perlre manual...

For anyone else who was puzzled about what the regular expressions
manual (perlre) had to do with it, he meant "perlref".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top