[Israel.pm] file handle in hash?

Shmuel Fomberg semuelf at 012.net.il
Mon Oct 22 12:16:21 PDT 2007


Hi.

Oops.
What I meant to write is that this code works:
----------
use strict;
use warnings;
open my $fh, ">", "foofile.txt";
my %hh = (handle => $fh);
my $f2 = $hh{handle};
print $f2 "something";
-----------

while this code does not:
----------
use strict;
use warnings;
open my $fh, ">", "foofile.txt";
my %hh = (handle => $fh);
print $hh{handle} "something";
-----------

why?

(thanks, gabor)

Shmuel.

>-----Original Message-----
>From: Gabor Szabo
>Sent: Monday, October 22, 2007 8:36 PM
>To: Perl in Israel
>Subject: Re: [Israel.pm] file handle in hash?
>
>I don't know what does the second version
>do but it should not do it.
>
>%hh and $hh are different animals.
>
>Do you have use strict; use warnings; enabled on this snippet?
>
>Gabor
>
>On 10/22/07, Shmuel Fomberg <semuelf at 012.net.il> wrote:
>> Hello There.
>>
>> Can anyone please explain to me why the following code does not work:
>> -----Code
>> open my $fh, "<", "filename";
>> my %hh = (handle => $fh);
>> print $hh->{handle} "something";
>> -----End Code
>>
>> while the slightly modified code does work?
>> -----Code
>> open my $fh, "<", "filename";
>> my %hh = (handle => $fh);
>> my $f2 = $hh->{handle};
>> print $f2 "something";
>> -----End Code
>>
>> Aren't they suppose to be the same?
>>
>> Thanks,
>> Shmuel.





More information about the Perl mailing list