in reply to Re: Re: can't write a variable to a file
in thread can't write a variable to a file

You don't show where you are actually making the call to Savetofile. It needs to be somewhere after assigning to $savestr. Can you paste all the code, and explain (with examples) what you mean by 'if I pass "hello!" directly'.

A better solution might be to pass the string as a parameter to Savetofile:

$savestr = "whatever\n"; &Savetofile($savestr); sub Savetofile { my $string = shift; if (defined($string)) { # all the open/lock/print/close stuff goes here } }

Also can you please put your code in <code> tags, it makes it a lot easier to read! Thanks...