you can use *scalar* as filehandle. like this : my $fh; open $fh ">>somefile.txt" || die "file open error"; print $fh "bla bla"; close ($fh);
"Jos� nyimi" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... | | Hello, | | For some reasons, I would to write a sub that return an handle of a given file : | | $LOG=get_file_handle($file_name); | | So afterward I could say print $LOG "bla bla"; | | My first try | | --------------- | | #!/usr/bin/perl | use warnings; | use strict; | | my $file_name='test.log'; | my $FH=&get_file_handle($file_name); | print $FH "This is a test\n"; | sub get_file_handle{ | my ($filename)=@_; | open(LOG,">>$filename") || die "Can't open file $filename for append writing\n"; | return LOG; | } | | I got this error message : | | Bareword "LOG" not allowed while "strict subs" in used at ..... | | | | Second try | | --------------- | | #!/usr/bin/perl | use warnings; | use strict; | | my $file_name='test.log'; | my $FH=&get_file_handle($file_name); | print $FH "This is a test\n"; | sub get_file_handle{ | my ($filename)=@_; | open(LOG,">>$filename") || die "Can't open file $filename for append writing\n"; | my $fh=*LOG{IO}; | return $fh; | } | | | | work ! | | But I don't see how can I keep it work whitout using typeglob (*LOG{IO}). | | Do you have an other way to do it ? | | TMTOWTDI ;-) | | Thanks, | | | | Jos�. | | | | | | | | | --------------------------------- | Yahoo! Mail -- Une adresse @yahoo.fr gratuite et en fran�ais ! | -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
