Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Hash refs and printing to FD

Reply
Thread Tools

Hash refs and printing to FD

 
 
January Weiner
Guest
Posts: n/a
 
      04-16-2009
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.
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-16-2009
January Weiner <(E-Mail Removed)> wrote in news:gs71l8$kum$1
@sagnix.uni-muenster.de:

> 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 <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
Reply With Quote
 
 
 
 
January Weiner
Guest
Posts: n/a
 
      04-16-2009
On 2009-04-16, A. Sinan Unur <(E-Mail Removed)> wrote:
> Follow the solution given in the documentation.


Thanks, Sinan!

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

j.
 
Reply With Quote
 
Tim McDaniel
Guest
Posts: n/a
 
      04-16-2009
In article <gs7657$m39$(E-Mail Removed)-muenster.de>,
January Weiner <(E-Mail Removed)> wrote:
>On 2009-04-16, A. Sinan Unur <(E-Mail Removed)> wrote:
>> Follow the solution given in the documentation.

>
>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".

--
Tim McDaniel, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Tad J McClellan
Guest
Posts: n/a
 
      04-16-2009
January Weiner <(E-Mail Removed)> wrote:
> On 2009-04-16, A. Sinan Unur <(E-Mail Removed)> wrote:
>> Follow the solution given in the documentation.

>
> Thanks, Sinan!
>
> I was looking for something in the perlre manual...



s/perlre/perlref/

??


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
January Weiner
Guest
Posts: n/a
 
      04-21-2009
On 2009-04-16, Tim McDaniel <(E-Mail Removed)> wrote:
> For anyone else who was puzzled about what the regular expressions
> manual (perlre) had to do with it, he meant "perlref".


)))

j.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Are weak refs slower than strong refs? John Nagle Python 3 02-25-2007 08:54 PM
Multiple Inheritance: mixed base class refs (hash, array) Alfred Z. Newmane Perl Misc 6 05-02-2005 07:04 PM
Printing an array of hash refs Tony N. Perl Misc 11 09-24-2004 03:59 PM
Question on refs inside hash rocknmetal20 Perl Misc 2 04-08-2004 08:05 AM



Advertisments