Hugh Loebner wrote:
> foreach my $fhkey ( keys %fh){
> open ( $fh{$fhkey}, ">$fhkey" ) ;
> }
Nobody mentioned this yet: Since you want your filehandles to be unique, why
not use the key of the hash instead of the value? In other words, change the
above to:
foreach my $fhkey ( keys %fh){
Because the first parameter passed to open
is the file handle. In the first case, there are 3 file handles: 1,2,3. In
the second case, the same file handle is used for each file, always ‘1’.
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Hugh Loebner
Sent: Fri
Hugh Loebner wrote:
> Hello perl gurus,
>
> I spent almost a whole day solving this problem. However, I wonder why
> it's a problem.
> #
> # The following program (which is what I started out with) will NOT work
> properly: Each eleme
At 09:20 AM 7/1/05 -0400, [EMAIL PROTECTED] wrote:
># this works fine, produces three files, aa , bb, cc with contents 'xxx aa
>xxx' etc
>
>my %fh = ( aa => 1, bb =>2, cc => 3) ; # note that each instance of
>$fh{$fhkey} has a different value
>
>foreach my $fhkey ( keys %fh){
>open ( $fh{$fhkey},
Title: Message
See
answers:
my %fh = ( aa => 1, bb =>2, cc => 3) ;
# note that each instance of $fh{$fhkey} has a different valueforeach my
$fhkey ( keys %fh){ open ( $fh{$fhkey}, ">$fhkey"
) ;## >so, you open 3 file handles,
one named "1", one named "2", and one named "3"