On Mon, Oct 01, 2001 at 07:46:24PM +0530, [EMAIL PROTECTED] wrote: > Instead of this behaviour of eval, Can I get what I want .i.e.. Can I > capture the output in some variable. Like here I am printing "hi" on > stdout. But I want this "hi" to be stored in some variable also.
So you want to store what you print in a variable, as well as print it out, and you think eval is the answer? It isn't. The simplest answer is: store what you're printing in a variable, then print it. my $stuff_to_print = "hi"; print $stuff_to_print; Now you have a variable, $stuff_to_print, with a value of "hi", and you've printed it out. You could also make your own print function that appends to the variable of your choice: sub append_and_print (\$@) { my($var_ref, @stuff_to_print) = @_; $$var_ref = '' unless defined($$var_ref); my $sep = defined($,) ? $, : ""; $$var_ref .= join($sep, @stuff_to_print); print @stuff_to_print; } append_and_print($stuff_to_print, "hi"); Now $stuff_to_print has the value "hi", and it's been printed. You could also setup a tied handle, one that appends to a variable on each print. The implementation is a little more complex, so I've omitted it. The bottom line is, what are you trying to accomplish with this? Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]