in reply to Re: How to open sub FH when filename is passed to sub?
in thread How to open sub FH when filename is passed to sub?


Thank you for your help.


I do want to write to file. In my program I use:


my $myhashname=$_;too.

Please help!

Replies are listed 'Best First'.
(jeffa) 3Re: How to open sub FH when filename is passed to sub?
by jeffa (Bishop) on May 05, 2002 at 16:08 UTC
    Then you probably want something like this:
    #!/usr/bin/perl -w use strict; create_hash('out_file.txt'); sub create_hash { my $filename = shift; my %hash; my @symbol = ('D'..'M'); my @protein = ( 'Aspartic Acid', 'Glutamic Acid', 'Phenylalanine', 'Glycine', 'Histidine', 'Isoleucine', 'Lysine', 'Leucine', 'Methionine', 'Asparagine', ); @hash{@symbol} = @protein; open(FILE,'>',$filename) or die "can't write $filename: $!"; while(my($key,$val) = each %hash) { print FILE "$key:$val\n"; } }

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)