On Mon, 17 Jan 2005 16:11:54 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
> Hi I need help regarding substituion of varaibles with values
> 
> Say I have a txt file (a.txt)
> 
> which has only one line:
> Hi $name
> 
> The PL file
> ========

  use strict;
  use warnings;

> open INPUT, "a.txt";

Always check the success of file opens!
  open INPUT, '< a.txt' or die "couldn't read a.txt: $!\n";

> my $name="Anish";
> my $temp="";
> while (<INPUT>)
> {
>   $temp=$temp.$_;

This could also be written as:
  $temp .= $_;
Personal preference, I guess.

> }
> close(INPUT);
> print "Content is: $temp";
> 
> In the output I want the $name to get as Anish..O/P like Hi Anish

Check out the eval built-in:
  close(INPUT);
  # evaluate the content of $temp as perl[1]
  # this won't work if there are any double quotes in $temp
  $temp = eval qq/"$temp"/;

There is probably a better way to do what you're trying to
accomplish... can you give us a bigger picture?

HTH,
Dave

[1] <http://www.perldoc.com/perl5.8.4/pod/func/eval.html>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to